Example usage for java.util Map put

List of usage examples for java.util Map put

Introduction

In this page you can find the example usage for java.util Map put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:Main.java

public static void main(String[] argv) {
    Map map = new HashMap();

    map.put("Adobe", "Mountain View, CA");
    map.put("IBM", "White Plains, NY");
    map.put("Learning Tree", "Los Angeles, CA");

    Iterator k = map.keySet().iterator();
    while (k.hasNext()) {
        String key = (String) k.next();
        System.out.println("Key " + key + "; Value " + (String) map.get(key));
    }/*from   w w  w . j  a v a 2  s .c o  m*/
}

From source file:MainClass.java

public static void main(String[] a) {

    Map map = new HashMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    Set set = map.entrySet();/*from w  w w  .j  a  va 2s.c o m*/

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    Map map = new HashMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    map.put(null, null);//from ww w  . j  av  a  2s.  com

    Set set = map.keySet();

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        System.out.println(iter.next());
    }
}

From source file:Main.java

public static final void main(String[] args) {
    Map<String, String> map = new HashMap<>();
    map.put("one", "a");
    System.out.println("Size = " + map.size());
    map.put(null, "b");
    System.out.println("Size = " + map.size());
    System.out.println("map.get(null) = " + map.get(null));
}

From source file:Main.java

public static void main(String args[]) {
    Map<Integer, String> mils = new HashMap<>();
    mils.put(1, "foo");
    mils.put(2, "bar");
    System.out.println("mils:\t" + mils);
    mils.put(1, "bar");
    System.out.println("mils:\t" + mils);
}

From source file:Main.java

public static void main(String[] args) {
    Map errors = new HashMap();

    errors.put("404", "A.");
    errors.put("403", "B.");
    errors.put("500", "C.");

    String errorDesc = (String) errors.get("404");
    System.out.println("Error 404: " + errorDesc);

    Iterator iterator = errors.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        System.out.println("Error " + key + " means " + errors.get(key));
    }/*w w  w. j  a  va2s .c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> map = new HashMap<>();
    map.put("CSS", "style");
    map.put("HTML", "mark up");
    map.put("Oracle", "database");
    map.put("XML", "data");

    map.forEach((String key, String value) -> {
        System.out.println("key=" + key + ",  value=" + value);
    });/*from   w  w  w .  j ava  2 s  .com*/

}

From source file:Main.java

public static void main(String[] s) {
    Hashtable<String, String> table = new Hashtable<String, String>();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    Map m = Collections.unmodifiableMap(table);

    m.put("key3", "value3");

    System.out.println(m);//from w w w.j  a v  a 2  s. co m

}

From source file:MainClass.java

public static void main(String[] s) {
    Hashtable table = new Hashtable();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    Map m = Collections.unmodifiableMap(table);

    m.put("key3", "value3");

    System.out.println(m);//from ww w  .  j a v a  2s. c o  m

}

From source file:Main.java

public static void main(String[] a) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");

    System.out.println(map.size());
}