class TreeSetDemo
{
public static void main(String[] args)
{
TreeSet ts = new TreeSet();
ts.add("cba");
ts.add("aaa");
ts.add("bca");
ts.add("abcd");
Iterator it = new Iterator();
while (it.hasnext();)
{
System.out.println(it.next());
}
}
}
class Student implements Comparable //该接口强制让学生具备比较性
{
private String name;
private int age;
public int compareto(Object obj)
{
if (!(obj instanceof Student))
throw new RuntimeException("不是学生对象");
Student s = (Student) obj;
if (this.age > s.age)
return 1;