Arrays.sort can be used only on array of elements which are Comparable (contain compareTo) method.
Also arrays of objects (like Strings) are filled with nulls and you can't invoke
null.compareTo("foo");
because null doesn't have any type, which also means no methods. It will simply throw NullPointerException when we try to execute such code.
What you need to do is use Arrays.sort(array, comparator) where your comparator will handle cases where it will be comparing nulls.
Lets say that we want to move all nulls at the end of array. Lets also assume case insensitive order of elements. In that case your code could look like
Arrays.sort(arr, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1 == null && o2 == null) return 0;// no swap needed
if (o1 == null) return 1;// null is bigger, swap left with right
if (o2 == null) return -1;// null is smaller
return String.CASE_INSENSITIVE_ORDER.compare(o1, o2);
}
});
Since Java 8 above code can simplified to
Arrays.sort(arr, Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER));
Arrays.sort(listaU, Comparator.nullsFirst(Comparator.naturalOrder()));ornullsLast.