The 30 second answer
I sort with a comparator on salary, usually descending, then thenComparing on name as a tie-break. For ordered streams that sort is stable. If names or salaries can be null I say so and use nullsLast so the ordering stays well defined.
List<Employee> sorted = emps.stream()
.sorted(Comparator.comparingDouble(Employee::salary).reversed()
.thenComparing(Employee::name))
.toList();Ordered-source sort is stable. For nulls: Comparator.nullsLast(...).
Sources:
Sources (0)
See inline citations in the answer above.