I have an array of Strings that are instances of a class from external code that I would rather not change.
I also have an array of ints that was generated by callin
In java you need to have two arrays one copy to sort off and the array you want to sort.
with a lambda:
String[] strings = new String[]{"string1", "string2", "string3", "string4"};
final int[] ints = new int[]{100, 88, 92, 98};
final List stringListCopy = Arrays.asList(strings);
ArrayList sortedList = new ArrayList(stringListCopy);
Collections.sort(sortedList, (left, right) -> ints[stringListCopy.indexOf(left)] - ints[stringListCopy.indexOf(right)]);
Or with Comparator:
String[] strings = new String[]{"string1", "string2", "string3", "string4"};
final int[] ints = new int[]{100, 92, 88, 98};
final List stringListCopy = Arrays.asList(strings);
ArrayList sortedList = new ArrayList(stringListCopy);
Collections.sort(sortedList, Comparator.comparing(s -> ints[stringListCopy.indexOf(s)]));