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

public static void main(String[] a) {

    Map map = new HashMap();
    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 args[]) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

    map.put(1, 2);/*from   w w  w.  j a v a  2 s  . c om*/
    map.put(2, 3);
    map.put(3, 4);

    for (Integer key : map.keySet()) {
        System.out.println(map.get(key));
    }
}

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

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

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

    System.out.println(map);//from  w ww.j a  v  a2s  . c o  m
}

From source file:Main.java

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

    // populate hash map
    newmap.put(1, "tutorials");
    newmap.put(2, "from");
    newmap.put(3, "java2s.com");

    System.out.println("Size of the map: " + newmap.size());
}

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

    System.out.println(map.containsKey("key1"));
    System.out.println(map.containsValue("value2"));
}

From source file:Main.java

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

    // populate hash map
    newmap.put(1, "tutorials");
    newmap.put(2, "from");
    newmap.put(3, "java2s.com");

    // check existence of key 2
    System.out.println("Check if key 2 exists: " + newmap.containsKey(2));
}

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 w  w w  .  j a  va2 s . co m

    System.out.println(map);
}

From source file:Main.java

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

    // populate hash map
    newmap.put(1, "tutorials");
    newmap.put(2, "from");
    newmap.put(3, "java2s.com");

    // check existence of value 'point'
    System.out.println("Check if value 'point' exists: " + newmap.containsValue("point"));
}

From source file:Main.java

public static void main(String args[]) {

    HashMap<Integer, String> newmap = new HashMap<Integer, String>();

    // populate hash map
    newmap.put(1, "tutorials");
    newmap.put(2, "from");
    newmap.put(3, "java2s.com");

    System.out.println(newmap.values());
}