Using java8, how can we sort the elements from the second element to the last?
list.stream().filter(student -> student.getAge()!=15).sorted(Comparator.comparing(student->student.getAge())).collect(Collectors.toList());
The last sorted list should contain all the elements, including the first.
I tried the code snippet:
Here I do not want to touch the first element. The above code is sorted from the second element to the last element. The problem is that I am not getting the first element (age = 15) in the output.
If I do not apply a filter, it sorts all the elements, and I lose the first element, which should not be.
Please help me with this. Thanks in advance.
source
share