Monday, October 4, 2010

Java Collections, some important facts

Here the main entry point, with an excellent tutorial by Joshua Bloch.

Collections can be: Set (TreeSet, HashSet), List (Vector, LinkedList), Queue (LinkedList), Map (HashMap, TreeMap, LinkedHashMap)

Some implementations are Synchronized (Vector), other no (ArrayList)

Collections provide Enumeration or Iterator to scan them.
Use Iterator when you might want to make changes to the collection, use Enumeration when R/O. You have also ListIterator

java.util.concurrent package provide thread-safe optimized implementation of most collections.

ArrayList and Vector use a dynamic array as an implementation,
LinkedList uses a doubly linked list, and it's faster for insert/delete

Queue: FIFO
Stack: LIFO

Interview questions here:

No comments: