Hello,
I have a question about ascending order sorting using the Comparabe interface:
When I add the keys of my Hash Map to a TreeSet object and implement the compareTo as below, I get descending order of sorting of names:
public int compareTo (Accounts a)
{
return a.name.compareTo(this.name);
}
// But when I change the above code to as below, it sorts the names in ascending order:
public int compareTo (Accounts a)
{
return this.name.compareTo(a.name);
}
Could someone explain me why?
Thank you!