In Java how do you sort one list based on another?

Using Java 8:

Collections.sort(listToSort, 
    Comparator.comparing(item -> listWithOrder.indexOf(item)));

or better:

listToSort.sort(Comparator.comparingInt(listWithOrder::indexOf));

Leave a Comment