So, I want to sort descending the array of doubles, and, accordingly to sort my array of strings. Both of my arrays have the same length.
This is how i do it (adapted from another answer in here):
arrayS contains the strings and array contains the doubles.
List<String> stringList = Arrays.asList(arrayS);
Collections.sort(stringList, Comparator.comparing(s -> array[stringList.indexOf(s)]));
I am getting out of bounds error on the second line.
More info:
System.out.println("arrayS: "+arrayS.length+" array: "+array.length);
out -> arrayS: 125 array: 125
arraythe same length asarrayS?doubleand theStringvalues are always paired, so when you sort the array, all is good.stringListwill also sort the underlyingarrayS. If that's your intent, you can just sort it directly usingArrays.sort().