I have constructed a series of nested ConcurrentHashMap
s initially with
private final ConcurrentHashMap<String, Object> allInOne =
new ConcurrentHashMap<String, Object>()
and subsequently with
ConcurrentHashMap<String, Object> accountMap =
(ConcurrentHashMap<String, Object>)allInOne.get(account);
accountMap.put("subAccounts", new ConcurrentHashMap<String, Object>());
ConcurrentHashMap<String, Object> subAccountMap =
(ConcurrentHashMap<String, Object>)accountMap.get(subAccount);
subAccountMap.put("subAccountData", new ConcurrentHashMap<String, Object>());
I want to loop through subAccountMap
, so I can grab specific values from subAccountData
.
I've tried all of the returned Enumeration
s and Set
s from the documentation, but I can't make it work because I'm still too new to Java to figure it out. Please show me how.
(I know what I'm doing is bad practice as many great stackers have shown me here and here, but all I'm trying to do is quickly get a working prototype and will clean up the code once finished)
You mean something like this?
ConcurrentMap subAccounts = allInOne.get(account).get("subaccounts");
for (String key : subAccounts.keySet()) {
Object subAccountObject = subAccounts.get(key);
}