I need to sort a list based on three parameters. This is how I do this.
SortedVehicles = new ArrayList<MyVehicle>(vehicles);
Collections.sort(SortedVehicles,Collections.reverseOrder());
@Override
public int compareTo(ITSVehicle v) {
if (this.getCapacity(0) < v.getCapacity(0)) return 1;
if (this.getCapacity(0) > v.getCapacity(0)) return -1;
if (this.getCapacity(0) == v.getCapacity(0))
{
if (this.getCapacity(1) < v.getCapacity(1)) return 1;
if (this.getCapacity(1) > v.getCapacity(1)) return -1;
}
if (this.getCapacity(1) == v.getCapacity(1))
{
if (this.getCapacity(2) < v.getCapacity(2)) return 1;
if (this.getCapacity(2) > v.getCapacity(2)) return -1;
}
return 0;
}
The problem is that I get 2 different sorting results:
Result 1
4490 5.77 306
4490 5.77 300
Result 2
4490 5.77 300
4490 5.77 306
getCapacity()return?