Thursday, August 11, 2016

LinkedList Quick Reference

Doubly-linked list implementation of the List and Deque interfaces.
Can be used in implementing Stack and Queue as it has methods/operations like peek, poll, offer, push, pop
In multi-threaded environment, to prevent accidental unsynchronized access to the LinkedList that can modify LinkedList structurally, wrap ArrayList using Collections.synchronizedList method
List list = Collections.synchronizedList(new LinkedList(...));

The iterators returned by this class's iterator and listIterator methods are fail-fast if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException.
Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. But one must not write program that depends on this behaviour.
boolean add(E e) method Appends the specified element e to the end of this list and after addition return true
boolean remove(Object o) method Removes the first occurrence of the specified element from this list and returns true if this list contained the specified element, else return false. Whereas, remove(int index) method removes the element at the specified position in this list and returns the removed element

Total Pageviews