import java.util.*;
public class TestSort {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
List<YuanShu> ys = new ArrayList<YuanShu>();
YuanShu y1 = new YuanShu();
y1.setT1(1324);
y1.setT2(345);
y1.setT3(436);
ys.add(y1);
YuanShu y2 = new YuanShu();
y2.setT1(23);
y2.setT2(8941);
y2.setT3(431412);
ys.add(y2);
YuanShu y3 = new YuanShu();
y3.setT1(786584);
y3.setT2(23452);
y3.setT3(43563);
ys.add(y3);
// 排序
Collections.sort(ys, new SortByYuanShu ());
for (YuanShu p : ys) {
System.out.print(p.getT1() + "\t" + p.getT2() + "\t" + p.getT3());
System.out.println();
}
}
}
class YuanShu {
private int t1;
private int t2;
private int t3;
public YuanShu() {
}
public int getT1() {
return t1;
}
public void setT1(int t1) {
this.t1 = t1;
}
public int getT2() {
return t2;
}
public void setT2(int t2) {
this.t2 = t2;
}
public int getT3() {
return t3;
}
public void setT3(int t3) {
this.t3 = t3;
}
}
// 排序
@SuppressWarnings("unchecked")
class SortByYuanShu implements Comparator {
public int compare(Object obj1, Object obj2) {
YuanShu y1 = (YuanShu) obj1;
YuanShu y2 = (YuanShu) obj2;
if (y1.getT1() < y2.getT1())
return 1;
else
return 0;
}
}