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<Integer, String> map = new HashMap<Integer, String>();

    map.put(1, "first");
    map.put(2, "second");
    // map.put(1, 2); <- Syntax error
}

From source file:com.home.ln_spring.ch5.env.EnvironmentSample.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.refresh();// w  w  w.ja v  a2  s .  co m

    ConfigurableEnvironment env = ctx.getEnvironment();
    MutablePropertySources propertySources = env.getPropertySources();
    Map appMap = new HashMap();
    appMap.put("user.home", "/home/vitaliy/NetBeansProjects/Ln_Spring");
    propertySources.addFirst(new MapPropertySource("SPRING3_MAP", appMap));

    System.out.println("user.home: " + System.getProperty("user.home"));
    System.out.println("JAVA_HOME: " + System.getProperty("JAVA_HOME"));

    System.out.println("user.home: " + env.getProperty("user.home"));
    System.out.println("JAVA_HOME: " + env.getProperty("JAVA_HOME"));
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("Pacific", "America/Los_Angeles");
    map.put("Mountain", "America/Denver");
    map.put("Central", "America/Chicago");
    map.put("Eastern", "America/New_York");
    ZoneId.of("Mountain", map);

}

From source file:Main.java

public static void main(String... args) {
    Map<String, MyData> map = new HashMap<String, MyData>();
    map.put("A", new MyData());

    System.out.println(map);/*from   www .  j a  v a2s.c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, Integer> map = new LinkedHashMap<>();

    map.put("Zero", 0);
    map.put("One", 1);
    map.put("Two", 2);
    map.put("Three", 3);
    map.put("Four", 4);

    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        System.out.println(entry.getKey() + " => " + entry.getValue());
    }/*from w  w w  .  j ava2 s .  co 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");
    map.remove("key3");

    System.out.println(map);//from w  w  w.j  a  v  a  2 s .  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");

    // Get the entry Set
    Set<Map.Entry<String, String>> entries = map.entrySet();

    entries.forEach((Map.Entry<String, String> entry) -> {
        String key = entry.getKey();
        String value = entry.getValue();
        System.out.println("key=" + key + ",  value=" + value);
    });// ww  w .j a  v a  2 s .co m

}

From source file:Main.java

public static void main(String[] args) {
    Map<String, Integer> map = new HashMap<String, Integer>();

    map.put("Age", 25);

    int age = map.get("Age");

    Integer newAge = age + 10;//w  ww . ja v  a  2  s .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");
    Map<String, String> map2 = new HashMap<String, String>();
    map2.put("key2", "value2");
    map2.put("key1", "value1");
    map2.put("key3", "value3");
    System.out.println(map1.equals(map2));
}

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<String, String> map2 = new HashMap<String, String>();
    map2.put("key2", "value2");
    map2.put("key1", "value1");
    map2.put("key3", "value3");
    System.out.println(map2.equals(map2));
}