Site Search:

Challenge 1 -- read the menu for maps


java.util.* and java.util.concurrent.*. 
Summary Map implementations
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.
  • 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 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.

Collection interfaces

click images to review the interface method signatures
When you are ready, click NEXT ->

Map Interfaces and Implementations






Map






SortedMap






NavigableMap






ConcurrentMap