How does Java know which String::compareTo
method reference to use when calling Collections.sort(someListOfStrings, String::compareTo);
? comp
OK, the source of Collections.sort() looks as follows:
public static void sort(List list, Comparator super T> c) {
Object[] a = list.toArray();
Arrays.sort(a, (Comparator)c);
ListIterator i = list.listIterator();
for (int j=0; j
I think it is quite clear now. The contents is a list. It means it has an order and the items are treated one by one in that order.