A Map of Map in Java is a nested data structure where the values of an outer Map are themselves Map objects. This structure allows for multi-level mapping, making it useful for scenarios where you need to associate a key with another map of key-value pairs.
Example:
java
Map<String, Map<String, Integer>> outerMap = new HashMap<>();
Map<String, Integer> innerMap = new HashMap<>();
innerMap.put(“Math”, 90);
innerMap.put(“Science”, 85);
outerMap.put(“John”, innerMap);
In this example, the key John maps to another Map containing subjects as keys and scores as values. Access data using:
java
System.out.println(outerMap.get(“John”)
This structure is ideal for hierarchical or complex relationships like a school system or a directory.