1

Ok, so I know there exist some really good threads about the cost of different operations on the Collection interface. When to use LinkedList<> over ArrayList<>? gives a great overview of the difference between ArrayList and LinkedList. But after reading that thread I am still unsure of one thing:

Is the algorithmic runtime of removeFirst()/pollFirst() and removeLast()/pollLast() O(1) or do i have to use an Iterator to achieve this?

Community
  • 1
  • 1
MoeRum
  • 15
  • 2

1 Answers1

0

If you refer to the javadoc:

All of the operations perform as could be expected for a doubly-linked list.

So removal of the head or tail is O(1).

assylias
  • 321,522
  • 82
  • 660
  • 783