Summay: The Map Interface, Collection implementations
-Maps store and retrieve elements with key values
e.g:
-Functions:
-Map has one child interface, SortedMap . A SortedMap maintains its key/value pairs sorted
in a particular order according to the key values.
-All of the methods of the Collection interface would appear to make sense for Map ,
except for iterator() . A Map , again, has two sets of objects: keys and values, and separate
iterators for each. This is why a Map does not implement Collection
-ConcurrentMap, It extends the base Map interface and adds atomic put, remove, and replace functionality that is
useful for concurrent programming
-Arrays are described as consuming constant time for retrieval, but linear time for insertion into or deletion from the body of the array.
-Arrays are useful when you are mostly reading or exclusively appending to the end of the collection.
-Link List holds its elements in a chain of nodes, each referencing the node before and after it (if any).
-Unlike the magic of an array, however, to retrieve an element from a linked list, you must traverse the list from either the head or
tail to reach the correct spot. As you might have guessed, this is a linear-time operation that gets more expensive as the number of elements grows.
-Linked lists are useful when you are doing a lot of insertions or deletions on a collection
-Trees are useful for maintaining and searching large collections of sorted elements.
-A hash map (or hash table, as it is also called) uses a mathematical hash algorithm applied to its key value to distribute its element
-Java Collections implementations
Interface | Implementation |
Set | HashSet LinkedHashSet CopyOnWriteArraySet EnumSet CopyOnWriteArraySet |
SortedSet | TreeSet ConcurrentSkipListSet |
List | ArrayList LinkedList Vector a Stack CopyOnWriteArrayList |
Map | HashMap EnumMap LinkedHashMap IdentityHashMap Hashtable a |
ConcurrentMap | ConcurrentHashMap ConcurrentSkipListMap |
SortedMap | TreeMap |
Queue / Dequeue | LinkedList ArrayDeque PriorityQueue DelayQueue SynchronousQueue ConcurrentLinkedQueue ConcurrentLinkedDequeue |
BlockingQueue | ArrayBlockingQueue LinkedBlockingQueue PriorityBlockingQueue |
Next Synchronized and Unsynchronized Collections...