In Java 8's Streams, I know how to filter a collection based on a predicate, and process the items for which the predicate was true. What I'm wondering is, if the predicate divides the collection into only two groups, is it possible through the API to filter based on the predicate, process the filtered results, then immediately chain on a call to process all elements excluded by the filter?
For instance, consider the following List:
List<Integer> intList = Arrays.asList(1,2,3,4);
Is it possible to do:
intList.stream()
.filter(lessThanThree -> lessThanThree < 3)
.forEach(/* process */)
.exclusions(/* process exclusions */); //<-- obviously sudocode
Or would I have to just do the forEach
process for the filtered items and then call stream()
and filter()
on the original list to then process the remaining items?
Thanks!