문제

I have constructed a series of nested ConcurrentHashMaps 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 Enumerations and Sets 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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top