import java.util.HashSet;
import java.util.Iterator;
import com.ncepu.bean.Student;
public class HashSet_Demo {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashSet<Student> ts = new HashSet<>();
ts.add(new Student("1141290214","马华高",21));
ts.add(new Student("1141290219","石勇志",20));
ts.add(new Student("1141290207","郭金涛",19));
System.out.println("======增强for循环遍历=======");
prt_1(ts);
System.out.println("====Iterator迭代器遍历=====");
prt_2(ts);
}
//增强for循环遍历
public static void prt_1(HashSet<Student> ts)
{
for(Student s : ts)
{
System.out.println(s.getSno()+"\t"+s.getName()+"\t"+s.getAge());
}
}
//迭代器遍历
public static void prt_2(HashSet<Student> ts)
{
Iterator<Student> it = ts.iterator();
while(it.hasNext())
{
Student s = it.next();
System.out.println(s.getSno()+"\t"+s.getName()+"\t"+s.getAge());
}
}
}