'Program Can't sort Employee List [closed]
I'am making a java program using streams which sort employee based on their salary. Program is given below :-
public class EmployeeMain {
public static void main(String[] args) {
Employee e1 = new Employee(10000, "Adam");
Employee e2 = new Employee(5000, "Peter");
Employee e3 = new Employee(14000, "Robin");
List<Employee> list = Arrays.asList(e1, e2, e3);
Collections.sort(list,
(emp1, emp2) -> e1.getSalary() > e2.getSalary() ? 1 : e2.getSalary() > e1.getSalary() ? -1 : 0);
list.stream().forEach(System.out::println);
}
}
The output for this code is :-
Employee [salary=10000, name=Adam]
Employee [salary=5000, name=Peter]
Employee [salary=14000, name=Robin]
What's the issue with this code?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
