I want to sort a list of string arrays by first element in each array element of same list, in reverse order, so 2, 1, 0
Here's what i tried so far:
List<String[]> array = new ArrayList<>();
String[] arr1 = {"0", "1/1"};
String[] arr2 = {"1", "1/2"};
String[] arr3 = {"2", "1/4"};
array.add(arr1);
array.add(arr2);
array.add(arr3);
Comparator<String[]> byFirstElement =
(String[] array1, String[] array2) -> Integer.parseInt(array1[0]) -
Integer.parseInt(array2[0]);
List<String[]> result = array.stream()
.sorted(array,byFirstElement) // error here
.collect(Collectors.toList());
The problem is that at sorted line i have an error highlighted, saying: "sorted(java.util.List, java.util.Comparator
.sorted(byFirstElement). Remove thearrayparameter.