I have a list of students and I want to bring only the leaderId on top of the same list following remains the remaining list items using Java Streams. I tried the below logic but it is not working as expected
List<Student> students = ....
Long leaderId = 123;
students.stream().sort((s1,s2) -> leaderId.equals(s1.getId()) || leaderId.equals(s2.getId()) ? 1: 0).collect(Collectors.toList());
Can anyone please give me some suggestion on this
Example
List of students:
[{id:121, name:"John"}, {id:131, name:"Susan"}, {id:123, name:"Jacob"}, {id:155, name:"Sunny"}]
Expected Output
[{id:123, name:"Jacob"}, {id:121, name:"John"}, {id:131, name:"Susan"}, {id:155, name:"Sunny"}]