Consider the following code:
List odd = new ArrayList();
List even = null;
List myList = Arrays.
Here is an example of how you could separate elements (numbers) of this list in even and odd numbers:
List myList = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
Map> evenAndOdds = myList.stream()
.collect(partitioningBy(i -> i % 2 == 0));
You would get lists of even/odd numbers like this (either list may be empty):
List even = evenAndOdds.get(true);
List odd = evenAndOdds.get(false);
You could pass any lambda with required logic in partitioningBy
.