Home | FAQ | Contact me

Lists and Maps

Class Data access particulars Operations Thread-safe version Notes
Individual Key-value Duplicate-
element
Order iteration Random access
FIFO Sorted LIFO By key By value By index
HashMap ConcurrentHashMap
LinkedHashMap Collections.synchronizedMap Retains insertion order.
TreeMap ConcurrentSkipListMap Ordered via Comparable (or Comparator).
HashSet ConcurrentHashMap< Key, Key >
LinkedHashSet ConcurrentHashMap< Key, Key > Retains insertion order.
ArrayList CopyOnWriteArrayList Retains insertion order.
PriorityQueue PriorityBlockingQueue
LinkedList (not thread-safe)
ArrayDeque ArrayBlockingQueue

Some notes on the table above:

Maps have key-value pairs whereas Lists and Queues have individual values. Some lists commonly contain multiple, identical elements (a list of a box of crayons might justifiably contain two blues).

Some sorted collections will behave as first-in, first-out, others last-in, last-out, and still others are just sorted.

Maps are typically accessed "by key" (why they can't contain duplicates), but LinkedList is accessed by index (position of the element in the list).

There are other, third-party maps and lists not illustrated here.