Javatpoint Logo
Javatpoint Logo

Map of Map in Java

In Java, Map is an interface that maps keys to values. Sometimes it is required to implement Map of Map (nested Map).

Nested Map is used in many cases, such as storing students' names with their Ids of different courses. In this case, we create a Map having a key, i.e., course name and value, i.e., another Map having a key, i.e., Id and value, i.e., the student's name.

We should use the following steps to create a Map of Map in Java:

  1. Take the total number of students from the user for each course.
  2. Fill in the student's information of all courses by taking input from the user.
  3. Fill the main Map by adding the course name as a key and user filled Map as a value.
  4. Within for loop, we first convert all the Map's keys into an ArrayList of type Object.
  5. After that, we get the object from the list by using the get() method and get value from the Map corresponding to this object for printing value.

Let's implement the logic for creating Map of Map to store data.


Map of Map in Java

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA