There are 2 unrelated problems with your code:
[1] There are two ways to write lambdas.
You can either write a single expression serving as the return value:
s.sort((a, b) -> a.length() - b.length());
Or you can involve a code block; but if you do that, return (and semicolons) have to show up:
s.sort((a, b) -> {
return a.length() - b.length();
});
Generally if you can make it work with a single expression, just do that; it's shorter. In your example you're using braces (so, the second form), but you don't have the return keyword nor the required semicolon.
Also, the types of the lambda arguments are optional. Generally if from context it is clear, just omit these: (a, b) -> a.length() - b.length()
[2] a comparator should return 0 if the arguments are equal, a negative number (any negative number, it doesn't matter which one) if a is 'smaller' than b, and a positive number if a is 'larger' than b. You are returning a boolean (you are using a greater than sign; the result of that expression is 'true' or 'false'; you need a number instead.
The solution seems trivial here: use minus instead.
[3] a bonus tip: There are utility methods for comparing based on field: Comparator.comparingInt(String::length) will do what you want in a way that is easier to read and less error prone. Also, instead of Collections.sort(list, comparator) you can just write list.sort(comparator); easier on the eyes, shorter, and more idiomatic.
Let's put it all together:
List<String> s = new ArrayList<>();
s.sort(Comparator.comparingInt(String::length));
Comparator.comparingInt(String::length)s.sort(Comparator.comparingInt(String::length));is preferable, just like the original example should have beenlistDevs.sort(Comparator.comparingInt(Developer::getAge));Using minus for comparators is a bad habit. It works here, as the values are never negative, but when sticking to the pattern for all numerical comparators, you will write broken comparators some day, as the difference between twointvalues can be larger than the value range ofint, leading to overflows. You can useInteger.compare(x, y)instead or just usecomparingInt