Object put(Object key, Object value) Associates key and value. : Map « Utility Classes « SCJP






import java.util.HashMap;
import java.util.Map;

public class MainClass {
  public static void main(String[] argv) {
    Map map = new HashMap();
    map.put("key", "value");
    // the older value is removed and returned
    map.put("key", "value new");
    System.out.println(map);
  }
}
{key=value new}








8.20.Map
8.20.1.Create a Hashtable and stores a Uniform Resource Locator (URL) String with a short String as a key
8.20.2.HashMap extends AbstractMap and is similar to Hashtable.
8.20.3.Maps differ from lists and sets in that they are ordered collections of key-value pairs.
8.20.4.Object put(Object key, Object value) Associates key and value.
8.20.5.Object get(Object key) Returns the value associated with key, or null if no value is associated with key.
8.20.6.boolean containsKey(Object key) Returns true if the Map associates some value with key.
8.20.7.void clear() Empties the Map.
8.20.8.Set keySet() Returns a Set containing the Map's keys.
8.20.9.Collection values() Returns a collection containing the Map's values.
8.20.10.A Hash Map's keys are iterated in unpredictable order.
8.20.11.A Tree Map's keys are iterated in natural order.
8.20.12.TreeMap class implements the java.util.SortedMap interface, which extends java.util.Map.
8.20.13.SortedMap: Object first() Returns this set's first key.
8.20.14.Object lastKey() Returns this set's last key.
8.20.15.SortedMap headMap(Object toKey) Returns a view of the portion of this sorted map whose keys are strictly less than toKey.
8.20.16.SortedMap tailMap(Object fromKey) Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey.
8.20.17.SortedMap subMap(Object fromKey, Object toKey) Returns a view of the portion of this sorted map whose keys range from fromKey, inclusive, to toKey, exclusive.
8.20.18.Maps check for key uniqueness