List of usage examples for java.util HashMap HashMap
public HashMap()
From source file:Main.java
public static void main(String[] argv) { Map<Number, String> numMap = new HashMap<Number, String>(); numMap.put(.5, "half"); numMap.put(1, "first"); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map map = new HashMap(); Object[] objectArray = map.keySet().toArray(); MyClass[] array = (MyClass[]) map.keySet().toArray(new MyClass[map.keySet().size()]); }
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: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 ww . jav a2 s. c o m*/ }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("a", 1); map.put("b", 2); System.out.println("Before removal"); for (String s : map.keySet()) { System.out.println(s);/* w w w.j av a 2 s . com*/ } System.out.println("\n\nAfter removal"); map.remove("a"); for (String s : map.keySet()) { System.out.println(s); } }
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"); map.clear();/*from ww w. j a v a 2 s . co 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"); 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)); }
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.containsKey("key1")); System.out.println(map.containsValue("value2")); }
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. j a v a 2 s . c o m*/ }