Java Collection Matrix - Java Collection Matrix
Java Collection Matrix - Java Collection Matrix
Random
Access
Key-Value
Pairs
Allows
Duplicates
Allows Null
Values
Thread Safe
YES
YES
NO
YES
YES
NO
NO
NO
HashMap
NO
YES
YES
NO
YES
NO
NO
NO
Vector
YES
YES
NO
YES
YES
YES
NO
NO
Hashtable
NO
YES
YES
NO
NO
YES
NO
NO
ArrayList
Blocking
Upper
Operations
Bounds
Most Commonly Known Collections
Usage Scenarios
* Default choice of List implementation
* To store a bunch of things
* Repetitions matters
* Insertion order matters
* Best implementation in case of huge lists which are read intensive
(elements are accessed more frequently than inserted deleted)
* Default choice of Map implementation
* Majorly used for simple in-memory caching purpose.
* Historical implementation of List
* A good choice for thread-safe implementation
* Similar to HashMap
* Do not allow null values or keys
* Entire map is locked for thread safety
HashSet
NO
YES
NO
NO
YES
NO
NO
NO
TreeSet
YES
YES
NO
NO
NO
NO
NO
NO
LinkedList
YES
NO
NO
YES
YES
NO
NO
NO
ArrayDeque
YES
YES
NO
YES
NO
NO
NO
NO
Stack
YES
NO
NO
YES
YES
YES
NO
NO
TreeMap
YES
YES
YES
NO
NO
NO
NO
NO
Special Purpose Collections
WeakHashMap
NO
YES
YES
NO
YES
NO
NO
NO
* The keys that are not referenced will automatically become eligible for
garbage collection
* Usually used for advanced caching techniques to store huge data and
want to conserve memory
Arrays
YES
YES
NO
YES
YES
NO
NO
YES
Properties
NO
YES
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
ConcurrentHashMap
NO
YES
YES
NO
NO
YES
NO
NO
ConcurrentSkipListMap
YES
YES
YES
NO
NO
YES
NO
NO
ConcurrentSkipListSet
YES
NO
NO
NO
NO
YES
NO
NO
CopyOnWriteArraySet
YES
YES
NO
NO
YES
YES
NO
NO
ConcurrentLinkedQueue
YES
NO
NO
YES
NO
YES
NO
NO
ConcurrentLinkedDeque
YES
NO
NO
YES
NO
YES
NO
NO
Blocking Collections
ArrayBlockingQueue
YES
NO
NO
YES
NO
YES
YES
YES
LinkedBlockingQueue
YES
NO
NO
YES
NO
YES
YES
YES
LinkedTransferQueue
YES
NO
NO
YES
NO
YES
YES
YES
PriorityBlockingQueue
YES
NO
NO
YES
NO
YES
LinkedBlockingDeque
YES
NO
NO
YES
NO
YES
SynchronousQueue
YES
NO
NO
YES
NO
YES
DelayQueue
YES
NO
NO
YES
NO
YES
Source:
NO