Often LinkedLists are selected for use because of the methods in this class. LinkedList has most of the common methods ArrayList has (add(), get(), set(), remove(), size(), etc) plus a number of new methods that can be very convenient:
addFirst(object) & addLast(object): adds the object to the beginning or end of the LinkedList.
peek(): This just returns the first element of the LinkedList. Appreciate this method name: The language architect here seemed to be feeling cutesy, which you don't see often.
poll():This returns and removes the first element of the LinkedList. Also this will return null if the LinkedListis empty.
offer(): Attempts to add object to the end of the LinkedLists, and returns a Boolean based on weather it was added or not.
removeFirst() & removeLast(): Returns and removes the last element.
No comments:
Post a Comment