Using Java 8:
Collections.sort(listToSort,
Comparator.comparing(item -> listWithOrder.indexOf(item)));
or better:
listToSort.sort(Comparator.comparingInt(listWithOrder::indexOf));
More Related Contents:
- How to sort a List/ArrayList?
- Removing Duplicate Values from ArrayList
- How to arrange the datas to display in array by given string of days in java?
- How to create a Java ArrayList in C
- ArrayList, Loop and requisite if can not work that i want – Java 11
- Why does my ArrayList contain N copies of the last item added to the list?
- How do I remove repeated elements from ArrayList?
- Sorting an ArrayList of objects using a custom sorting order
- How to avoid “ConcurrentModificationException” while removing elements from `ArrayList` while iterating it? [duplicate]
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- Convert list to array in Java [duplicate]
- Java List.add() UnsupportedOperationException
- How to randomize two ArrayLists in the same fashion?
- How can I sort a List alphabetically?
- Sorting arraylist in alphabetical order (case insensitive)
- Java 8 stream reverse order
- What is the difference between List and ArrayList? [duplicate]
- How to sort an ArrayList using multiple sorting criteria?
- List versus ArrayList as reference type?
- Sorting a list with stream.sorted() in Java
- Java List Sorting: Is there a way to keep a list permantly sorted automatically like TreeMap?
- Simple way to compare 2 ArrayLists
- Sort List in reverse in order
- What is a List vs. an ArrayList? [duplicate]
- Java Sort List of Lists
- Why can’t you have a “List” in Java? [duplicate]
- ArrayList vs LinkedList from memory allocation perspective
- Finding out if a list of Objects contains something with a specified field value?
- new ArrayList() failing in Java
- Sorting ArrayList of Objects by Object attribute