java.util.* and java.util.concurrent.*.
implements | Sorted? | Calls hashCode? | Allow null as key? | |
HashMap | Map |
No | Yes |
Yes |
Hashtable | Map |
No | Yes |
No |
LinkedHashMap | Map |
No |
Yes |
Yes |
TreeMap | NavigableMap |
Yes |
No | No |
ConcurrentHashMap | ConcurrentMap |
No |
Yes |
No |
ConcurrentSkipListMap | ConcurrentNavigableMap |
Yes |
No | No |
public interface Map<K, V>
- default V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)
- default V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction)
- default V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)
- ...
- Set<Map.Entry<K, V>> entrySet()
- default void forEach(BiConsumer<? super K, ? super V> action)
- default V getOrDefault(Object key, V defaultValue)
- default V merge(K key, V value, BiFunction<? super K, ? super V, ? extends V> remappingFunction)
- void putAll(Map<? extends K, ? extends V> m)
- default V putIfAbsent(K key, V value)
- default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
- Collection<V> values()
public interface SortedMap<K, V> extends Map<K, V>
All keys inserted into SortedMap must implement Comparable interface or be accepted with Comparator. Ordering provided by Comparable or Comparator much be consistent to equals if the SortedMap is to implement the Map interface.
All keys inserted into SortedMap must implement Comparable interface or be accepted with Comparator. Ordering provided by Comparable or Comparator much be consistent to equals if the SortedMap is to implement the Map interface.
- Comparator<? super K> comparator()
- K firstKey()
- SortedMap<K, V> headMap(K toKey)
- K lastKey()
- SortedMap<K, V> subMap(K fromKey, K toKey)
- SortedMap<K, V> tailMap(K fromKey)
public interface NavigableMap<K, V> extends SortedMap<K, V>
The following methods returns the closest matches for given search targets, returns null if there is no such key.
The following methods returns the closest matches for given search targets, returns null if there is no such key.
< | > | <= | >= | |
return K | lowerKey(K key) |
higherKey(K key) | floorKey(K key) |
ceilingKay(K key) |
return Map.Entry<K,V> | lowerEntry(K key) | higherEntry(K key) | floorEntry(K key) |
ceilingEntry(K key) |
- NavigableSet<K> descendingKeySet()
- NavigableMap<K, V> descendingMap()
- Map.Entry<K, V> firstEntry()
- Map.Entry<K, V> pollFirstEntry()
- Map.Entry<K, V> lastEntry()
- Map.Entry<K, V> pollLastEntry()
public interface ConcurrentMap<K, V> extends Map<K, V>
Classes that implements ConcurrentMap suppose to provide thread safety and atomicity.
Actions in a thread prior to placing an object in the ConcurrentMap as key or value happens before
actions subsequent access or removal of that object from ConcurrentMap in another thread
For aggregate operations such as clear and putAll, concurrent retrievals may reflect the insertion and removals of only some entries.
Aggregate status methods size, isEmpty and containsValue are only an estimates instead of accurate value if multiple threads are updating the map.
Iterators are designed to be used by one thread at a time.
Classes that implements ConcurrentMap suppose to provide thread safety and atomicity.
Actions in a thread prior to placing an object in the ConcurrentMap as key or value happens before
actions subsequent access or removal of that object from ConcurrentMap in another thread
For aggregate operations such as clear and putAll, concurrent retrievals may reflect the insertion and removals of only some entries.
Aggregate status methods size, isEmpty and containsValue are only an estimates instead of accurate value if multiple threads are updating the map.
Iterators are designed to be used by one thread at a time.
Collection interfaces
click images to review the interface method signaturesWhen you are ready, click NEXT ->