I am trying to sort my custom class array-list using Collections.sort by declaring my own anonymous comparator. But the sort is not working as expected.
My code is
Collections.sort(arrlstContacts, new Comparator<Contacts>() {
public int compare(Contacts lhs, Contacts rhs) {
int result = lhs.Name.compareTo(rhs.Name);
if(result > 0)
{
return 1;
}
else if (result < 0)
{
return -1;
}
else
{
return 0;
}
}
});
The result is not in sorted order.