I have following class. In this, Iris is another class with some attributes.
public class Helper {
Iris iris;
double distance;
public Helper(Ir
Why don't you get your Helper class to implement Comparable interface and then use the in-built sort method offered by the Collections class.
Collections.sort(helperList)
I think that would solve the problem. Plus, this sort method is stable.
http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#sort%28java.util.List%29
http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html
Implementing Comparable interface:
public class Helper implements Comparable{
Iris iris;
double distance;
public Helper(Iris iris, double distance) {
this.iris = iris;
this.distance = distance;
}
public int compareTo(Helper other) {
return new Double(this.distance).compareTo(new Double(other.distance));
}
}