Map Interface HashMap TreeMap
Map Interface
Key-value pair collections with unique keys.
Map Examples
MaphashMap = new HashMap<>(); Map treeMap = new TreeMap<>(); hashMap.put("Java", 1); hashMap.put("Python", 2); Integer value = hashMap.get("Java"); // 1 hashMap.containsKey("Java"); // true
Key Points
- HashMap: unordered, null keys allowed.
- TreeMap: sorted by keys.
- LinkedHashMap: insertion order.
- Keys must have proper
hashCode() equals().