Collections Flashcards
General collection interfaces
(Collection, Set, Map, List, Queue, SortedSet, SortedMap)
Interfaces extending Collection. Is Map part of Collection interface?
List, Set, Queue
Map is not collection
TreeSet vs TreeMap
TreeMap allows duplicate values, TreeSet - no
TreeMap is sorted based on keys while TreeSet is sorted based on objects
HashMap vs Hashtable
Hashtable is synchronized, whereas HashMap is not.
Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
Requirements for implementation of hashCode to achieve best performance
uniform distribution
alwasy return the same value for same object
same value for equal objects
Differences between Hashtable and ConcurrentHashMap
ConcurrentHashMap uses multiple locks
Hashtable uses single lock
ConcurrentHashMap locking is applied only for updates. In case of retrievals, it allows full concurrency
EnumSet, EnumMap
EnumSet, EnumMap - their elements/keys come from a single enum type
WeakHaskMap
the keys of the map are stored in a weakreference
key-value pairs can dynamically be dropped from the map when the only reference to the key is from the weak reference
IdentityHashMap
using reference-equality in place of object-equality when comparing keys (and values)
Implementation details of about ConcurrentHashMap. Synchronization.
lock on buckets instead of whole map
Iterator and modification of a List. ConcurentModificationException.
occurs when something we are iterating is changed