I am trying to retrieve the keys of hashmap.
I am using to hashmap as follows:
HashMap<String, String> inner = new HashMap<String, String>();
HashMap<HashMap<String,String>, String> outer = new HashMap<HashMap<String,String>, String>();
I am putting values in both the hashmap as follows:
inner.put("1", "one");
inner.put("2", "two");
inner.put("3", "three");
outer.put(inner, "outer1");
outer.put(inner, "outer2");
Now I want to get the output as
1 one outer1
1 one outer2
2 two outer1
2 two outer2
3 three outer1
3 three outer2
But I am unable to get this. Can you please help me to solve this.
Edited code:
HashMap<String, String> inner = new HashMap<>();
HashMap<String, String> inner1 = new HashMap<>();
HashMap<HashMap<String, String>, String> outer = new HashMap<>();
outer.put(inner, "outer1");
outer.put(inner1, "outer2");
inner1.put("1", "one");
inner1.put("2", "two");
inner1.put("3", "three");
inner1.put("4", "three");
inner.put("1", "one");
inner.put("2", "two");
inner.put("3", "three");
inner.put("4", "three");
outer.forEach((k,v) -> {
k.forEach((k1, v1) -> System.out.println(k1 + " " + v1 + " " + v));
});