List of usage examples for java.util HashMap HashMap
public HashMap()
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hm = new HashMap<String, String>(); hm.put("4", "four"); hm.put("3", "three"); hm.put("1", "one"); hm.put("2", "two"); Map<String, String> treeMap = new TreeMap<String, String>(hm); System.out.println(treeMap);//from w w w . j a v a 2 s.c o m }
From source file:Main.java
public static void main(String args[]) { // create two hash maps HashMap<Integer, String> newmap1 = new HashMap<Integer, String>(); HashMap<Integer, String> newmap2 = new HashMap<Integer, String>(); // populate hash map newmap1.put(1, "tutorials"); newmap1.put(2, "from"); newmap1.put(3, "java2s.com"); // clone 1st map newmap2 = (HashMap) newmap1.clone(); System.out.println("1st Map: " + newmap1); System.out.println("Cloned 2nd Map: " + newmap2); }
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); });/*from www . j a v a 2s . c om*/ }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> db = new HashMap<Integer, String>(); db.put(1000, "1000"); db.put(1011, "1011"); db.put(1102, "1102"); db.put(2023, "2023"); db.put(2034, "2034"); TreeMap<Integer, String> db2 = new TreeMap<Integer, String>(db); System.out.println(db2);// ww w.j av a 2s. c o m }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hashmap = new HashMap<String, String>(); hashmap.put("one", "1"); hashmap.put("two", "2"); hashmap.put("three", "3"); hashmap.put("four", "4"); hashmap.put("five", "5"); hashmap.put("six", "6"); Iterator<String> keyIterator = hashmap.keySet().iterator(); Iterator<String> valueIterator = hashmap.values().iterator(); while (keyIterator.hasNext()) { System.out.println("key: " + keyIterator.next()); }/*from www . jav a 2 s.c o m*/ while (valueIterator.hasNext()) { System.out.println("value: " + valueIterator.next()); } }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("1", "first"); hashMap.put("2", "two"); hashMap.put("3", "from java2s.com"); Map<String, String> weakHashMap = new WeakHashMap<String, String>(hashMap); }
From source file:Main.java
public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>(); // add some values in the map map.put("One", 1); map.put("Two", 2); map.put("Three", 3); LinkedHashMap<String, Integer> linkMap = new LinkedHashMap<String, Integer>(map); System.out.println(linkMap);// w ww .j a v a2 s . co m }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> myMap = new HashMap<String, Integer>(); myMap.put("a", 1); myMap.put("b", 2); myMap.put("c", 3); Set<String> stStrKeys = myMap.keySet(); Iterator<String> itrs = stStrKeys.iterator(); while (itrs.hasNext()) { String s = itrs.next();//from w ww .j a va2 s.co m System.out.println(s + ": " + myMap.get(s)); } }
From source file:Main.java
public static void main(String args[]) { HashMap<String, String> hmap = new HashMap<String, String>(); hmap.put("1", "A"); hmap.put("2", "B"); hmap.put("3", "C"); hmap.put("4", "from java2s.com"); // get typesafe view of the map Map<String, String> tsmap = Collections.checkedMap(hmap, String.class, String.class); System.out.println(tsmap);// w ww .j a v a 2 s. c o m }
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 ww .j a v a 2s.co m*/ Set set = map.keySet(); Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } }