《class MyBean implements Comparable{
public int compareTo(Object obj){
if(! obj instanceof MyBean)
throw new ClassCastException() //具体异常的名称,我要查jdk文档。
MyBean other = (MyBean) obj;
return age > other.age?1:age== other.age?0:-1;
}
}
class MyTreeSet {
private ArrayList datas = new ArrayList();
public void add(Object obj){
for(int i=0;i<datas.size();i++){
if(obj.compareTo(datas.get(i) != 1){
datas.add(i,obj);
}
}
}
}
》
|
|