In my previous question - How to filter the age while grouping in map with list I was able to find the name to age groups using List<User> users. Now I am trying to find the different User groups from ages according to the threshold. I tried this
List<User> userAboveThreshold = users.stream().filter(u -> u.getAge() > 21).collect(toList());
List<User> userBelowThreshold = users.stream().filter(u -> u.getAge() <= 21).collect(toList());
This time it works I can see using
userAboveThreshold.forEach(u -> System.out.println(u.getName() + " " + u.getAge()));
userBelowThreshold.forEach(u -> System.out.println(u.getName() + " " + u.getAge()));
But I have to access the users list again to find the complimentary list. Can this not be done simpler?