public static void main(String[] args) {
TreeSet<Double> ts = new TreeSet<Double>(new Comparator<Double>() {
@Override
public int compare(Double d1, Double d2) {
double num = d2 - d1 ;
return num == 0 ? 1 : (int)num;
}
});
ts.add(1.1);
ts.add(5.2);
ts.add(6.3);
ts.add(2.5);
ts.add(5.2);
ts.add(3.3);
for (Double d : ts) {
System.out.println(d);
}
}
|
|