Professional Documents
Culture Documents
List: List Names New Linkedlist : O (1) (Size, Get, Set, ... ), O (N) - Add Operation
List: List Names New Linkedlist : O (1) (Size, Get, Set, ... ), O (N) - Add Operation
List: List Names New Linkedlist : O (1) (Size, Get, Set, ... ), O (N) - Add Operation
(2) LinkedList [all operation O(1) (including add() ), except for retrieving n-th element which is O(n).]
Adding/deletion is not expensive
Double LinkedList
Queue:
(1) Priority Queue
(2) Dequeue
(2) Hashtable
Synchronized
No null key / Value
Slow & more memory
(3) SortedMap: Key based sorting
(4) ConcurrentHashMap
List
Set
Queue
Map
An object that maps keys to values. A map cannot duplicate keys; each key can map to at most one
value.
Method to calculate hash : [Division method, Folding method, Mid Square method,
module multiplication method]
java.util.HashMap :
Not thread safe, need to use synchronised operation when manipulating form
multiple threads
Iteration not guaranteed in insertion order
java.util.LinkedHashMap
Insertion order is preserved
Doubly linked list is used internally, which means extra space
java.util.TreeMap
Implementation of SortedMap & NavigableMap
“Natural sorted” order of key, i.e. keys are sorted in ASC order.
Red black tree (Specific type of balanced search tree / self-balancing binary
search tree) based implementation
Key should implement Comparable interface
o If not then ClassCast Exception will be thrown
o Or provide an explicit Comparator in constructor
java.util.IdentityHashMap
java.util.EnumMap
All keys must come from a single Enum type
Null key not permitted, not synchronized
Java.util.WeakHashMap
ConcurrentHashMap
While one thread is Iterating the HashMap object, if another thread tries to add/modify
the contents of the Object then we will get a Run-time exception saying
ConcurrentModificationException. Whereas In ConcurrentHashMap we won’t get any
exception while performing any modification at the time of Iteration.
In HashMap, null values are allowed for key and values, whereas in
/ZX/?/ConcurrentHashMap null value is not allowed for key and value, otherwise, we will
get a Run-time exception saying NullPointerException.
If the bucket contains a small number of nodes (< 8), it uses a LinkedList for all of
this bucket's nodes.
If the bucket contains a large number of nodes (=> 8), it dynamically replaces it with
an ad-hoc implementation of treemap, for all of this bucket's nodes.
ArrayList:
How to Synchronize (ThreadSafe) ArrayList in Java