I have a Set of numbers :
Set<Integer> mySet = [ 1,2,3,4,5,6,7,8,9]
I want to divide it into 2 sets of odds and evens.
My way was to use filter twice :
Set<Integer> set1 = mySet.stream().filter(y -> y % 2 == 0).collect(Collectors.toSet())
Set<Integer> set2 =mySet.stream().filter(y -> y % 2 != 0).collect(Collectors.toSet())
I don't like this solution because I go over the whole set twice.
Is there any smarter way to do it?