This is what I have:
class Person {
Integer id;
String name;
}
// A list of persons:
List<Person> persons
// Now I have something like this:
List<Integer> ids // where the ids are stored in an specific order
Basically I wanna sort the persons list in the same order like the ids.
Is there a better way then use like two loops and create a new Person-List?
regards && tia
noircc
Use
Collections.sortusing a customComparatoras shown below. The comparator gets the ids of the persons being compared and works out in which order they appear in the ids list:Note: this code assumes that the ids of all persons in the list will appear in the ids list.