The Map Interface in Java


Map stores key-value pairs, where each key is unique. HashMap, TreeMap, and LinkedHashMap are implementations of the Map interface.

Source Code

Map map = new HashMap();
map.put("Alice", 30);
map.put("Bob", 25);
System.out.println(map.get("Alice")); // Outputs "30"

Use Map when you need efficient lookups/searches by keys and to store key-value associations.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments