Mapmap = new HashMap<>(); map.put("one", 1); map.put("two", 2); int value = map.get("one"); // returns 1
MapIn this example, we create a Map that maps Integer keys to String values. We add two key-value pairs to the map and then retrieve the value associated with the key 2. The `java.util.Map` interface is part of the Java standard library, so it does not require any additional packages or libraries.map = new LinkedHashMap<>(); map.put(1, "one"); map.put(2, "two"); String value = map.get(2); // returns "two"