【发布时间】:2021-11-08 23:16:50
【问题描述】:
我有一个字符串元素列表,我想应用过滤器将列表分成两个子列表,以“el”开头的元素和其他元素。 有没有办法只使用一个过滤器来划分列表?
List elements = List.of("e1", "el2", "el3", "4 el", "5 el")
示例:
elements.stream()
.filter(s -> s.startWith("el))
.collect( /* something that hold both the element that pass the filter and element that does not */ )
【问题讨论】: