A Map stores key-value pairs and does not allow duplicate keys.

Common Implementations

ImplementationFeaturesBest For
HashMap<K, V>Fast lookups, no orderGeneral-purpose mapping
LinkedHashMap<K, V>Maintains insertion orderIteration in order of insertion
TreeMap<K, V>Sorted keys (uses Comparable or Comparator)Sorted key-value retrieval
Hashtable<K, V>Thread-safe version of HashMapMulti-threaded applications

Example: Using HashMap

import java.util.HashMap;
import java.util.Map;
 
public class MapExample {
    public static void main(String[] args) {
        Map<String, Integer> scores = new HashMap<>();
        scores.put("Alice", 90);
        scores.put("Bob", 85);
        scores.put("Charlie", 92);
 
        System.out.println(scores.get("Alice")); // Output: 90
    }
}