class Solution {
public int[] Sort(int[] nums) {
int[] arr = {1, 2, 3, 4, 5};
Arrays.sort(arr, (a, b) -> (a+""+b).compareTo((b+""+a)));//this part is showing error
return arr;
}
}
Can anyone please tell me why this code is not working?
I am trying to sort an array based on concatenated results.
Not sure I understand your problem correctly, but this is one way to sort it with logic you initially showed.
In this case we use
.boxed()to convert frominttoIntegerso we have.sorted()available to use. Actual concat sort algo you can adjust to your liking, and then we map tointand collect to array.