list_java270.2

View Code
package list_java270_2;

import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeSet;

public class Test {


    public static void main(String[] args) {
           HashSet<Student> st=new HashSet<Student>();
           
           Student st1=new Student(10010, "xiao");
           st.add(st1);
           
           Student st2=new Student(10011, "hha");
           st.add(st2);
           
           Student st3=new Student(10014, "jia");
           st.add(st3);
           
           Student st4=new Student(10015, "hong");
           st.add(st4);
           
           Iterator<Student> t=st.iterator();
           
           while(t.hasNext()){
               Student r=t.next();
               System.out.println("ID:"+r.getID()+"  Name:"+r.getName());
           }
    }

}
原文地址:https://www.cnblogs.com/aijianiula/p/2623087.html