List of usage examples for java.util HashMap HashMap
public HashMap()
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"); // get keyset value from map Set keyset = newmap.keySet(); // check key set values System.out.println("Key set values are: " + keyset); }
From source file:Main.java
public static void main(String[] argv) { Map map = new HashMap(); map.put("Adobe", "Mountain View, CA"); map.put("IBM", "White Plains, NY"); map.put("Learning Tree", "Los Angeles, CA"); Iterator k = map.keySet().iterator(); while (k.hasNext()) { String key = (String) k.next(); System.out.println("Key " + key + "; Value " + (String) map.get(key)); }//w w w . j ava2s .c om }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map map = new HashMap(); for (Iterator it = map.values().iterator(); it.hasNext();) { Object value = it.next(); }//from w w w. j a va2 s.co m }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map map = new HashMap(); for (Iterator it = map.keySet().iterator(); it.hasNext();) { Object key = it.next();//from ww w. j a v a 2 s . c o m } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map map = new HashMap(); for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); }// www. j a va2 s . c o m }
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<Integer, String> map = new HashMap<>(); for (int i = 0; i < 10; i++) { map.putIfAbsent(i, "val" + i); }//from www. j a va 2s .co m map.forEach((id, val) -> System.out.println(val)); map.computeIfPresent(3, (num, val) -> val + num); System.out.println(map.get(3)); // val33 map.computeIfPresent(9, (num, val) -> null); System.out.println(map.containsKey(9)); // false map.computeIfAbsent(23, num -> "val" + num); System.out.println(map.containsKey(23)); // true map.computeIfAbsent(3, num -> "bam"); System.out.println(map.get(3)); // val33 }
From source file:Main.java
public static void main(String[] args) { Map errors = new HashMap(); errors.put("404", "A."); errors.put("403", "B."); errors.put("500", "C."); String errorDesc = (String) errors.get("404"); System.out.println("Error 404: " + errorDesc); Iterator iterator = errors.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); System.out.println("Error " + key + " means " + errors.get(key)); }//w ww. j ava 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { Map<String, String> oldMap = new HashMap<String, String>(); oldMap.put("a", "1"); oldMap.put("A", "2"); Map<String, String> newMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); newMap.putAll(oldMap);//from w w w .java 2 s .co m String value = newMap.get("a"); System.out.println(value); }
From source file:Main.java
public static void main(String[] a) { Map<String, String> yourMap = new HashMap<String, String>(); yourMap.put("1", "one"); yourMap.put("2", "two"); yourMap.put("3", "three"); Map<String, String> sortedMap = new TreeMap<String, String>(yourMap); System.out.println(sortedMap); }