HashMapmap = new HashMap<>(); map.put("apple", 1); map.put("banana", 2); map.put("orange", 3); int value = map.get("banana"); System.out.println(value); // outputs 2
HashMapmap = new HashMap<>(); map.put("apple", 1); map.put("banana", 2); map.put("orange", 3); map.remove("banana"); System.out.println(map); // outputs {apple=1, orange=3}
HashMapThe java.util HashMap values library is part of the Java Standard Library.map = new HashMap<>(); map.put("apple", 1); map.put("banana", 2); map.put("orange", 3); for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); int value = entry.getValue(); System.out.println(key + ": " + value); } // outputs: // apple: 1 // banana: 2 // orange: 3