Saturday, January 11, 2025
HomeProgrammingMap of Map in Java

Map of Map in Java

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.

See also  Top 10 IDEs for Programmers

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:

See also  C Functions

java

System.out.println(outerMap.get(“John”)

This structure is ideal for hierarchical or complex relationships like a school system or a directory.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x