I need to sort an array according to another array, eg:
list1: [221, 54, 50, 138, 125, 145]
list2: [50, 125]
then the sorted list1 should be: [50, 125 ,221, 54, 138, 145]
I tried the following code:
Collections.sort(list1, Comparator.comparing(listItem -> list2.indexOf(listItem)));
But this results in: [221, 54, 138, 145, 50, 125]
How can I get the 50 and 125 at the top and the rest after?