I have List of Student object
And the Student object has
public class Student{
private String name;
private String town;
// getters,setters and toString method
}
And my List<Student>
looks like :
List<Student> list = new ArrayList<Student>();
list.add(new Student("abc","xtown"));
list.add(new Student("bcd","ytown"));
list.add(new Student("cdf","xtown"));
list.add(new Student("fgh","Atown"));
And another list is
List<String> list1 = new ArrayList<>();
list1.add("bcd");
list1.add("cdf");
list1.add("fgh");
list1.add("abc");
I need to sort the list based on list1.
My output would be
[Student [name=bcd,town=ytown],
Student [name=cdf,town=xtown],
Student [name=fgh,town=Atown],
Student [name=abc,town=xtown]]