Help to understand the logic of the program. We have 3 arrays of strings, they are written in ArrayList, I sort them by the number of elements in the sheet. What I can not understand: how is this sorting done? What's going on here?
Comparator<String[]> sortByLength = new Comparator<String[]>() { @Override public int compare(String[] o1, String[] o2) { return o1.length - o2.length; } };
public class T{ public static void main(String[] args) { String[] array1 = {"ΠΌΠ°ΠΌΠ°", "ΠΌΡΠ»Π°", "ΡΠ°ΠΌΡ"}; String[] array2 = {"Ρ", "ΠΎΡΠ΅Π½Ρ", "Π»ΡΠ±Π»Ρ", "java"}; String[] array3 = {"ΠΌΠΈΡ", "ΡΡΡΠ΄", "ΠΌΠ°ΠΉ"}; List<String[]> arrays = new ArrayList<>(); arrays.add(array1); arrays.add(array2); arrays.add(array3); Comparator<String[]> sortByLength = new Comparator<String[]>() { @Override public int compare(String[] o1, String[] o2) { return o1.length - o2.length; } }; arrays.sort(sortByLength); for (String[] str : arrays) { System.out.println(Arrays.toString(str)); } } }