| 
 
| import java.util.*; class  HashSetDemo
 {
 public static void main(String[] args)
 {
 HashSet ht = new HashSet();
 ht.add(new Student("小五",19));
 ht.add(new Student("地方",139));
 ht.add(new Student("小df",129));
 ht.add(new Student("小dfaaadf",197));
 Iterator it = ht.iterator();
 while(it.hasNext())
 {
 System.out.println(it.next().name);
 /*提示找不到符号,为什么it.next().getClass()方法返回的是Student对象,为什么it.next().name这条语句会出现错误*/
 }
 }
 }
 class Student
 {
 public String name;
 public int num;
 public Student(String name,int num)
 {
 this.name = name;
 this.num = num;
 }
 }
 | 
 |