for sorting based on person name we can implement compare (Object o1, Object o2) method of Comparator in Java or Java Comparator class.

public class PersonSortByPerson_ID implements Comparator{

public int compare(Person o1, Person o2) {
return o1.getPersonId() – o2.getPersonId();
}
}

Read more: http://javarevisited.blogspot.com/2011/06/comparator-and-comparable-in-java.html#ixzz1vlldKyY3

Advertisements