Am new to java i have formed a set of result in
`Map<String, Map<String, List<String>>>`
now i want to get the keys and values of each set
How should get this. anyone please suggest me
thanks in advance.
Am new to java i have formed a set of result in
`Map<String, Map<String, List<String>>>`
now i want to get the keys and values of each set
How should get this. anyone please suggest me
thanks in advance.
You will want to look at the documentation for Map
s.
myArbitrarilyNamedMap = new Map<String, Map<String, List<String>>>();
//do stuff so that myArbitrarilyNamedMap contains values
Set firstLevelKeys = myArbitrarilyNamedMap.keySet(); //this bit
For me is much easier to study with examples. I can give you a little example. May be it will be usefull.
public class MapHierarchy {
public static void main(String[] args) {
// preparation
Map<String, Map<String, List<String>>> myTestMap = new HashMap<>();
ArrayList<String> listOfValues = new ArrayList<>();
listOfValues.add("Hello");
listOfValues.add("my");
listOfValues.add("little");
listOfValues.add("friend");
HashMap<String, List<String>> innerMap = new HashMap<>();
innerMap.putIfAbsent("innerMapKey", listOfValues);
myTestMap.put("outerKey", innerMap);
// where the magic happens
System.out.println("Keys of outer map: " + myTestMap.keySet().toString());
for (Map.Entry<String, List<String>> innerMapItem : innerMap.entrySet()) {
String innerMapItemKey = innerMapItem.getKey();
System.out.println("Key of inner map: " + innerMapItemKey);
System.out.println("Values of inner map: " + innerMapItem.getValue().toString());
}
}}