1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| HashMap<Integer,String> hashMap1 = new HashMap<>();
HashMap<Integer,String> hashMap = new HashMap<>(hashMap1);
hashMap.put(1,"my value is 1");
hashMap.putIfAbsent(1,"my value is 1"); hashMap.remove(1); hashMap.remove(1,"my value is 2"); hashMap.get(1); hashMap.getOrDefault(1, 0); hashMap.set(1, "new value") hashMap.containsKey(1); hashMap.containsValue("whose value is 2"); hashMap.forEach((key1, value1) -> { }); for (Map.Entry(Integer, String) entry : hashMap.entrySet()) { System.out.println(entry.getKey()); System.out.println(entry.getValue()); }
TreeMap<Integer,String> treeMap = new TreeMap<>((a,b)->{ return a-b; });
|