标题: 如何让一个Set集合有序的排列 [打印本页] 作者: 刘冲 时间: 2013-9-30 14:36 标题: 如何让一个Set集合有序的排列 下面有个程序,需要按照一定的规则进行显示出来,应该怎么做?
public class SetDemo{
private String name;
private int age;
private Person person;
public SetDemo(){}
public SetDemo(String name, int age, Person person){
this.name = name;
this.age = age;
this.person = person;
}
}
class Person{
private String cardId;
private int sex;
public void setCardId(String cardId){
this.cardId = cardId;
}
public String getCardId(){
return this.cardId;
}
public void setSex(int sex){
this.sex = sex;
}
public int getSex(){
return this.sex;
}
}
public class Test{
public static void main(String[] args){
SetDemo sd = new SetDemo();
Set<SetDemo> set = new HashSet<SetDemo>();
set.add(new SetDemo("",20,new Person()));
}
}