[英]How to return a HashMap within a HashMap
I am trying to return the first inner HashMap of the outer HashMap, but this method I am using does not work.我试图返回外部 HashMap 的第一个内部 HashMap,但我使用的这个方法不起作用。
public HashMap<String, Integer> getMap(HashMap<String, HashMap<String, Integer>> allQs) {
HashMap <String, Integer> value = allQs.getValue();
return value;
}
How can I return the object as a HashMap?如何将对象作为 HashMap 返回?
FYI: HashMap does not maintain the insertions order if order matters then use LinkedHashMap.仅供参考:如果顺序很重要,则 HashMap 不维护插入顺序,然后使用 LinkedHashMap。
And also Hashmap does not have any method getValue()
;而且 Hashmap 没有任何方法
getValue()
;
If you want to get the first value then use如果你想获得第一个值然后使用
for(HashMap<String,Integer> innerMap : map.values())
{
return innerMap;
}
or或者
map.values().stream().findFirst().get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.