Similar to my previous question here, the User objects I have are these
new User("ayush","admin",23)
new User("ashish","guest",19)
new User("ashish","admin",20)
new User("garima","guest",29)
new User("garima","super",45)
new User("garima","guest",19)
Now I am trying to get the name to varying ages trend for these users. But I need to filter them above a threshold age. I could get the trend using
Map<String, List<Integer>> userNameAndAgeTrend = users.stream().collect(Collectors.groupingBy(user-> user.getName(), Collectors.mapping(u-> u.getAge(), toList())));
this gives me {ashish=[19, 20], garima=[29, 45, 19], ayush=[23]}. But I am unable to filter the List properly using threshold for example 21 years in my situation using such grouping. Can someone please help?
Also, using .filter(user -> user.getAge() > 21) gives no mapping for ashish, which is what I want to store too. I can use Java10 installed on my machine and trying the suggested solutions.