I have a requirement where a map contains values which were the keys of other maps. Like below example
Map<String, String> keysMap = new HashMap<>();
one.put("Car","4 Wheeler");
one.put("Bike","2 Wheeler");
Map<String, String> m1 =new HashMap<>();
m1.put("4 Wheeler","KIA");
m1.put("2 Wheeler","Bajaj");
Map<String, String> m2 = new HashMap<>();
m2.put("4 Wheeler","Hyundai");
m2.put("2 Wheeler","KTM");
List<Map<String, String>> listOfMaps= new ArrayList<>();
listOfMaps.add(m1);
listOfMaps.add(m2);
List<Map<String, String>> result= new ArrayList<>();
for(Map<String, String> eachMap: listOfMaps){
Map<String, String> singleMap = new HashMap<>();
}
Now I want keys of first map(one) as key to each new map(singleMap) for the values of second map(two) and third map(three) and so on
Required output should be like
[
{ Car: "KIA", Bike: "Bajaj" },
{ Car: "Hyundai", Bike: "KTM" },
]
What I have tried:
I'm new to java and want to get a solution to thr above problem. I have tried getting all the values from keysMap and store it in a list and tried to iterate over the list of maps. But it seems very difficult to understand