In this case, you can use the link to the method:
List<Integer> f = new LinkedList<>();
Collections.sort(f, Integer::compare);
There is no return statement in the source code:
Collections.sort(f, (f1 , f2) -> {
return Integer.compare(f1,f2);
});
return should be used if lambda contains{}
The same without return and brackets:
Collections.sort(f, (f1 , f2) ->
Integer.compare(f1,f2)
);
Some useful notes from the comments section below:
You can use Collections.sort(f)and rely on the natural order. Jean-Francois Savard
Java 8 List sort, f.sort(null); f.sort(Comparator.naturalOrder()); , Collections.sort(f, Comparator.naturalOrder()); Holger