What is the time complexity of LinkedList.getLast() in Java?

Posted by i. on Stack Overflow See other posts from Stack Overflow or by i.
Published on 2010-05-04T13:37:15Z Indexed on 2010/05/04 13:38 UTC
Read the original article Hit count: 130

Filed under:
|
|
|

I have a private LinkedList in a Java class & will frequently need to retrieve the last element in the list. The lists need to scale, so I'm trying to decide whether I need to keep a reference to the last element when I make changes (to achieve O(1)) or if the LinkedList class does that already with the getLast() call.

What is the big-O cost of LinkedList.getLast() and is it documented? (i.e. can I rely on this answer or should I make no assumptions & cache it even if it's O(1)?)

© Stack Overflow or respective owner

Related posts about java

Related posts about Performance