The question is unclear so I’ll try to answer, but listing my assumptions.
If my assumptions are incorrect, then ofcourse the answer is going to be incorrect.
I am assuming that the {domains={A={ notation does not mean you have this as text but that you have a map containing a map, containing a map.
I am assuming you want to get at the inner map of A, B, C
this would work like this:
public Map<String,String> getDomainProperties(Map map, String domainName) {
if (!map.containsKey("domain") {
return null; // or throw an exception if you prefer.
}
Map domainMap = map.get("domain");
if (!domainMap.containsKey(domainName)) {
return null; // or throw IllegalArgumentException or similar if you prefer
}
return (Map<String,String>) domainMap.get(domainName);
}
you get some warnings about casting because the input map is not specified. From your example it would be something like:
Map<String, Map<String, Map<String, String>>> but that seemed a bit messy to write in the example
1
solved Java splitting map from a nested map [closed]