Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Collections [List, Set, Queue, Map]

List [AbstractList [ArrayList, Vector], LinkedList] :: an ordered collection(sequence),


allow duplicate elements, allow multiple null elements, zero-based indexing, provides
special iterator called ListIterator that allows element insertion, replacement and bi-
directional access.

AbstractList:- provides skeletal impl of List to minimize the effort required to impl List
interface.

ArrayList:- Resizable array, permits all elements(+nulls), provides—ensureCapacity


operation, Not synchronized, synchronization can be achieved by—
Collections.synchronizedList(new ArrayList(….)).

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.

Set [AbstractSet [HashSet [LinkedHashSet], TreeSet] :: no duplicates, at most one


null element, take care while using mutable objects as Set elements.

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(….)).

Map[HashMap, Hashtable [Propertie], TreeMap, etc.]

HashMap:- Unsynchronized, permit a null as key, no constant order. Any object can act
as a key.

Hashtable:- synchronized, nulls are not allowed.

Properties:- Persistent set of properties.

TreeMap;- elements sorted in order of keys[ascending /natural /constructor] i.e. only


integer keys, Unsynchronized.

List: Ordered collection of objects, allows duplicates, nulls.


Set: Un-ordered collection of objects, do not allow duplicates, allows at most one null.
Map: Is a ‘set’ of Key-Value pair of objects, no duplicate keys.
Stack: A Stack is a Last-In-First-Out (LIFO) container; only top element can be seen,
‘push’ and ‘pop’ are main operations.
Queue: A Queue is First-In-First-Out (FIFO), i.e. an element joins the Queue at the
'rear', and leaves / removed from the 'front'.

You might also like