Interface Map<K,V>

Type Parameters:
K - The key type (keys must be unique)
V - The value type
All Known Subinterfaces:
SortedMap<K,V>
All Known Implementing Classes:
AbstractHashMap, AbstractMap, AbstractSortedMap, AVLTreeMap, ChainHashMap, ProbeHashMap, RBTreeMap, SortedTableMap, SplayTreeMap, TreeMap, UnsortedTableMap

public interface Map<K,V>
An interface for an associative map which binds a key uniquely to a value. This interface is a simplified version of java.util.Map.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an iterable collection of all key-value entries of the map.
    get(K key)
    Returns the value associated with the specified key, or null if no such entry exists.
    boolean
    Tests whether the map is empty.
    Returns an iterable collection of the keys contained in the map.
    put(K key, V value)
    Associates the given value with the given key.
    remove(K key)
    Removes the entry with the specified key, if present, and returns its associated value.
    int
    Returns the number of entries in the map.
    Returns an iterable collection of the values contained in the map.
  • Method Details

    • size

      int size()
      Returns the number of entries in the map.
      Returns:
      number of entries in the map
    • isEmpty

      boolean isEmpty()
      Tests whether the map is empty.
      Returns:
      true if the map is empty, false otherwise
    • get

      V get(K key)
      Returns the value associated with the specified key, or null if no such entry exists.
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the associated value, or null if no such entry exists
    • put

      V put(K key, V value)
      Associates the given value with the given key. If an entry with the key was already in the map, this replaced the previous value with the new one and returns the old value. Otherwise, a new entry is added and null is returned.
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Returns:
      the previous value associated with the key (or null, if no such entry)
    • remove

      V remove(K key)
      Removes the entry with the specified key, if present, and returns its associated value. Otherwise does nothing and returns null.
      Parameters:
      key - the key whose entry is to be removed from the map
      Returns:
      the previous value associated with the removed key, or null if no such entry exists
    • keySet

      Iterable<K> keySet()
      Returns an iterable collection of the keys contained in the map.
      Returns:
      iterable collection of the map's keys
    • values

      Iterable<V> values()
      Returns an iterable collection of the values contained in the map. Note that the same value will be given multiple times in the result if it is associated with multiple keys.
      Returns:
      iterable collection of the map's values
    • entrySet

      Iterable<Entry<K,V>> entrySet()
      Returns an iterable collection of all key-value entries of the map.
      Returns:
      iterable collection of the map's entries