import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Tester{
public static void main(String[] args) {
List<Human> humans = new ArrayList<Human>();
humans.add(new Human(13));
humans.add(new Human(33));
humans.add(new Human(21));
humans.add(new Human(21)); // line 1
HumanComparator c = new HumanComparator(); // line 2
Collections.sort(humans, c); // line 3
System.out.print(humans.get(0).age);
Collections.sort(humans); // line 4
System.out.print(humans.get(0).age);
}
}
class Human implements Comparable<Human> {
Integer age;
public Human(int age) {
this.age = age;
}
public int compareTo(Human h) {
return h.age.compareTo(this.age);
}
}
class HumanComparator implements Comparator<Human> {
public int compare(Human h1, Human h2) {
return h1.age.compareTo(h2.age);
}
}