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:Pizza.java

public static void main(String... args) {
    Map<String, Pizza> pizzaStock = new HashMap<String, Pizza>();

    pizzaStock.put("cheese", new CheesePizza());
    pizzaStock.put("veggie", new VeggiePizza());
    System.out.println(pizzaStock);
}

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");
    Set set = map.entrySet();/*from w ww . jav  a2  s .c om*/

    Iterator iter = set.iterator();

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

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");
    map.put(null, null);/*from   w  ww .  j  av  a 2  s  .c  om*/

    Map<String, String> map2 = new HashMap<String, String>();
    map2.put("key4", "value4");
    map2.put("key5", "value5");
    map2.put("key6", "value6");
    map.putAll(map2);

    System.out.println(map);
}

From source file:PassEnv.java

public static void main(String[] args) throws java.io.IOException {
    System.out.println(System.getProperty("java.class.path"));
    ProcessBuilder pb = new ProcessBuilder("java", "Env", "DRAGONBALLS");
    Map<String, String> env = pb.environment();
    env.put("DRAGONBALLS", "7");
    pb.start();//w w  w  . ja v  a2  s .  c o  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Map<String, String> map = new LinkedHashMap<String, String>();

    map.put("1", "value1");
    map.put("2", "value2");
    map.put("3", "value3");
    map.put("2", "value4");

    for (Iterator it = map.keySet().iterator(); it.hasNext();) {
        Object key = it.next();//  www.  j  a va 2  s . c  o  m
        Object value = map.get(key);
    }
}

From source file:Main.java

public static void main(String[] argv) {

    Map<String, URL> urlMap = new HashMap<String, URL>();
    try {// www  . j a  v a  2  s.  com
        urlMap.put("java", new URL("http://www.java2s.com"));
    } catch (MalformedURLException e) {
    }
    String s = urlMap.get("java").getHost();
}

From source file:Helper.java

public static void main(String[] args) {

    Map<String, Integer> m = new HashMap<String, Integer>();

    m.put("A", 42);
    m.put("B", 3);
    m.put("C", 1);

    System.out.println(Helper.get(m, "forty-two", -1));
    System.out.println(Helper.get(m, "A", -1));
    System.out.println(Helper.get(m, "B", -1));
    System.out.println(Helper.get(m, "something_else", -1));

}

From source file:ProcessBuilderDemo.java

public static void main(String argv[]) throws InterruptedException, IOException {

    List<String> command = new ArrayList<String>();
    command.add("notepad");
    command.add("foo.txt");
    ProcessBuilder builder = new ProcessBuilder(command);
    Map<String, String> environ = builder.environment();
    environ.put("PATH", "/windows;/windows/system32;/winnt");
    builder.directory(new File(System.getProperty("user.home")));

    final Process godot = builder.start();

    godot.waitFor();//from  www. j a  v a2  s.  co  m

    System.out.println("Program terminated!");
    return;
}

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");

    System.out.println("Map: " + map.toString());

    listValues(map);/* w ww. j a  v  a2s.  com*/
    listEntries(map);
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> m1 = new LinkedHashMap<String, String>();
    m1.put("1", "One");
    m1.put("3", "Three");

    Map<String, String> m2 = new LinkedHashMap<String, String>();
    m2.put("2", "Two");
    m2.put("4", "Four");

    List<String> list = new ArrayList<String>();
    list.addAll(m1.keySet());/*  w  ww.  j  av a  2s.c  o m*/
    list.addAll(m2.keySet());
    for (String s : list) {
        System.out.println(s);
    }
}