I've got two ArrayList<JLabel>:
ArrayList<JLabel> label1 = new ArrayList<JLabel>();
ArrayList<JLabel> label2 = new ArrayList<JLabel>();
label1 contains names (like "John" or "car") and label2 contain ratings (like "8.5" or "10.0"). I wanna sort both lists by rating.
I've used Collections.sort(label2, new Sort()); to sort label2, but I have no idea how to sort label1 in exaclty the same way (using label2 objects). Here is my Comparator class:
class Sort implements Comparator<JLabel>{
public int compare(JLabel o1, JLabel o2) {
Double a = Double.parseDouble(o1.getText());
Double b = Double.parseDouble(o2.getText());
return b.compareTo(a);
}
}
Any ideas?