【发布时间】:2016-06-07 11:54:36
【问题描述】:
我有一张类似的地图
contractAttributesMap=new HashMap<String,WsContractAttribute>();
contractAttributesMap.put("entityDisplayName", new WsContractAttribute("label_contractmap_entityDisplayName","entityDisplayName",WsContractAttribute.AttriibuteType.TEXT));
contractAttributesMap.put("entityNumber",new WsContractAttribute("label_contractmap_entityNumber","entityNumber",WsContractAttribute.AttriibuteType.TEXT));
//other code
我想从键列表中获取值,例如键列表,即键名称列表。
我知道一种方法
private static List<WsContractAttribute> getContractAttributes(Set<String> fields){
for(String fieldName:fields){
contractAttributesMap.entrySet()
.parallelStream()
.filter(e -> e.getKey().contains(fieldName))
.map(e -> e.getKey())
.collect(Collectors.toList());
}
}
但不是循环,我想将此列表本身传递到流 api 中,这将过滤匹配的值并返回列表。 这是可能的。! 提前致谢。
【问题讨论】:
-
也许你正在寻找类似
fields.stream().map(contractAttributesMap::get).collect(toList())的东西? -
是的,非常感谢:)
标签: java java-stream