I have a list of objects that I want to sort using different properties.
@Override
public int compareTo(Object obj)
{
Field tab = (Field) obj;
int objx = Integer.parseInt(tab.getX());
// int objy = Integer.parseInt(tab.getY());
int classX = Integer.parseInt(this.X);
if (classX == objx)
return 0;
else if (classX > objx)
return 1;
else
return -1;
}
What I have so far:
Collections.sort(list1); // But using property1 to sort
Collections.sort(list1); // But using property2 to sort
So, in first case I'm able to sort using property1, but how to sort using property2?
I'm trying to sort using different parameters, but compareTo()
accepts only one.