Java Collections
Java Collections
AbstractList:- provides skeletal impl of List to minimize the effort required to impl List
interface.
Vector:- Synchronized, always larger in size than needed capacity due to capacity
incrementation. Iterators on vector are fail-fast, i.e. throws
ConcurrentModificationException if structurally changed while iterating.
LinkedList:- linked list impl of list, permits all elements(+nulls), Not synchronized,
synchronization can be achieved by—Collections.synchronizedList(new ArrayList(….)),
provides additional methods to get, remove, insert elements at beginning and end of list
—these operations allow LinkedList to be used as stack, queue or dqueue.
AbstractSet:- provides skeletal impl of Set to minimize the effort required to impl Set
interface.
HashSet:- (backed by hash table, i.e. HashMap instance), No order, permits null element,
Iterators on HashSet are fail-fast, Not synchronized, synchronization can be achieved by
—Collections.synchronizedSet(new HashSet(….)).
LinkedHashSet:- Hash table and linked list implementation of Set interface, Insertion
order, Iterators on HashSet are fail-fast, Not synchronized, synchronization can be
achieved by—Collections.synchronizedSet(new LinkedHashSet(….)).
TreeSet:- (backed by TreeMap instance), elements sorted in order [ascending /natural
/constructor], null not allowed, Iterators on TreeSet are fail-fast, Not synchronized,
synchronization can be achieved by—Collections.synchronizedSet(new TreeSet(….)).
HashMap:- Unsynchronized, permit a null as key, no constant order. Any object can act
as a key.