我有一个HashMap
具有以下结构。Map<String, Container>
本Container
类包含一个List
。我想清除这个列表中的内容,这样的列表中存在,但与0元素。后来,我将再次把它的值。
在replaceAll()
期望一个BiFunction
。由于这下面是给编译错误,因为返回类型clear()
是void
:
personMap.replaceAll((k,v) -> v.getMyList().clear());
您可以使用此:
map.values().forEach(i -> i.getMyList().clear());
另外,您可以使用此:
map.values().stream()
.map(Container::getMyList)
.forEach(List::clear);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句