This question has an answer for how to sort a List with a multi-line lambda expression:
list.sort((o1, o2) -> {
int cmp = o1.getGroup().compareTo(o2.getGroup());
if (cmp == 0)
cmp = Integer.compare(o1.getAge(), o2.getAge());
if (cmp == 0)
cmp = o1.getName().compareTo(o2.getName());
return cmp;
});
Unfortunately, this does not seem to work for a raw array int[] arr:
Arrays.sort(arr, (int1, int2) -> {
// some lambda, various if-else statements for example
});
How to use a multi-line lambda expression in Arrays.sort() to sort a raw array?
I'm fine with any other approach (does not have to use Arrays.) as long as it uses lambda expressions (no comparators).
arr = Arrays.stream(arr).boxed().sorted((int1, int2) -> { /* your logic */ }).mapToInt(Integer::intValue).toArray();would work.