lets us suppose I have a Employee list as :
private static List<Employee> list = new ArrayList<Employee>();
static {
list.add(new Employee("Joe", 100000, 1980));
list.add(new Employee("Tim", 50000, 1982));
list.add(new Employee("Mike", 90000, 1970));
list.add(new Employee("Rick", 50000, 1955));
list.add(new Employee("Andy", 60000, 1966));
list.add(new Employee("Tim", 10000, 1995));
list.add(new Employee("Tony", 130000, 1991));
list.add(new Employee("Timmy", 150000, 1988));
list.add(new Employee("Rich", 50000, 1980));
list.add(new Employee("Andrew", 160000, 1970));
list.add(new Employee("Ton", 150000, 1958));
list.add(new Employee("Jose", 40000, 1970));
list.add(new Employee("Timothy", 50000, 1996));
list.add(new Employee("Ricardo", 50000, 1988));
list.add(new Employee("Gemasio", 60000, 1971));
list.add(new Employee("Mike", 80000, 1992));
}
Now what i want is to generate the list which do some filtering like: salary > x and salary < y and sort according to the employee name and then again sort if multiple employee have same name but different salary but now using their salary
what I have done so far is :
System.out.println(
list.stream()
.filter(e -> e.getSalary() > 55000)
.filter(e -> e.getSalary() < 120000)
.sorted(Comparator.comparing(Employee::getName))
.collect(Collectors.groupingBy(Employee::getName))
);
for eg: after sorting only name i got::
<name: Andy salary: 60000 year of birth: 1966>,
<name: Gemasio salary: 60000 year of birth: 1971>,
<name: Joe salary: 100000 year of birth: 1980>,
<name: Mike salary: 90000 year of birth: 1970>,
<name: Mike salary: 80000 year of birth: 1992>
here are two mike but now Within this two Mike I want to sort their salary in decendeing form so that new result will be:
<name: Andy salary: 60000 year of birth: 1966>,
<name: Gemasio salary: 60000 year of birth: 1971>,
<name: Joe salary: 100000 year of birth: 1980>,
<name: Mike salary: 80000 year of birth: 1970>,
<name: Mike salary: 90000 year of birth: 1992>
and except Mike i dont want to change other orders
but i am not able to get the desired result will anyone please help me out what is wrong or what i need to do to further from here. Thanks :)