如何使用公共密钥从地图的内部地图获取所有值? [英] How to get all values from the inner maps of a map using a common key?
本文介绍了如何使用公共密钥从地图的内部地图获取所有值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张地图地图: HashMap< String,Map< DistinctCode,String>>
。
I have a map of maps: HashMap<String, Map<DistinctCode, String>>
.
我需要通过使用 DistinctCode从内部地图中提取
。我怎么能在一行或一个声明中做到这一点? String
值
I need to extract the String
value from the inner maps just by using a DistinctCode
. How can I do that in one line or statement?
换句话说,我需要一个像这样的方法:
In other words, I need a method something like this:
mapOfMap.find(distinctcode)
是否可行在一行或一个声明?
Is it doable in one line or statement?
推荐答案
在Java 8中
List<String> list = map.values().stream().map(m -> m.get(distinctcode)).filter(Objects::nonNull).collect(Collectors.toList());
这篇关于如何使用公共密钥从地图的内部地图获取所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文