implements an interface Comparator< T >
class A implements Comparator < Person > {
@Override
public int compare(Person o1, Person o2) {
if(o1.getName() != null && o2.getName() != null){
return o1.getName().compareTo(o2.getName());
}
return 0;
}
}
then use Collections.sort(/* list here */, /* comparator here*/)
user467871
source
share