Example usage for java.util HashMap HashMap

List of usage examples for java.util HashMap HashMap

Introduction

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

Prototype

public HashMap() 

Source Link

Document

Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).

Usage

From source file:Main.java

public static void main(String[] args) {
    ZoneId z = ZoneId.of("UTC", new HashMap<>());

    System.out.println(z);//from   w w  w . ja  v a2  s  .com
}

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.clear();//  w w w .  j a va  2  s .c o  m

    System.out.println(map);
}

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.containsKey("key1"));
    System.out.println(map.containsValue("value2"));
}

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.clear();//from  www  . j  a  v  a 2 s. c o  m

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

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);/*ww  w  .  j  av a 2  s.  c  om*/
}

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.get("key2"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Map map = new HashMap();
    Object[] objectArray = map.values().toArray();
    MyClass[] array = (MyClass[]) map.values().toArray(new MyClass[map.values().size()]);

}

From source file:Main.java

public static void main(String[] args) {
    HashMap<Character, Integer> map = new HashMap<Character, Integer>();
    String test = "BUNANA";
    char[] chars = test.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        if (!map.containsKey(chars[i])) {
            map.put(chars[i], 1);/* w ww . j  a v  a 2s .c o m*/
        }
        map.put(chars[i], map.get(chars[i]) + 1);
    }

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

From source file:Main.java

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

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

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