Java append `HashMap` values to existing HashMap if key matches
问题 I have below HashMap(to.String()) printed below. HashMap<String, HashMap<String, HashMap<String, Integer>>> abc = new HashMap<>(); HashMap abc = {disabled={account={testConfiguration=1, iterate=1}}} I want to append {group={iterate=1}} to existing map if key disabled matches. Finally my map should look like below, how can I achieve it? HashMap abc = {disabled={account={testConfiguration=1, iterate=1}, {group={iterate=1}}} 回答1: I think you want this: abc.computeIfPresent("disabled", (k,v) -> {