简体   繁体   English

我怎么能结合两个哈希图<String, Integer>到一个 HashMap <HashMap<String, String> , 整数&gt;?

[英]How could I combine two hash maps of <String, Integer> to one HashMap of <HashMap<String, String>, Integer>?

HashMap<String1, Integer1> 和 HashMap<String2, Integer2> 到 HashMap<HashMap<String1,String2> , Integer1+Integer2>

see hashmap contains Map(Key, Value) so if you want to merge the hashmap then you are changing the key.看到 hashmap 包含 Map(Key, Value) 所以如果你想合并 hashmap 那么你正在改变键。 so if you want to add multiple keys then you can do it with所以如果你想添加多个键,那么你可以用

Map<Map.Entry<String,String>, Integer> map = new HashMap<>();

map.put(Map.entry("onekey", "2nd Keys"), 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM