I have a List of my user defined class.
class Customer{
Integer age;
String name;
//getter & setter
}
Collections.sort(customerList, new Comparator <Customer>() {
public int compare(Customer o1, Customer o2) {
// TODO Auto-generated method stub
if(o1.getAge()!=null && o2.getAge() != null)
return o1.getDistance().compareTo(o2.getDistance());
else
return 1;
}
});
Now my age variable may have a null value or the age of the customer. All null values should be appended at the end and remaining values should sorted in ascending or descending order(anything is ok)?
But this code is throwing an exception :
java.lang.IllegalArgumentException: Comparison method violates its general contract!
Please tell me what to do? Thanks in advance.