import java.util.*;
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name=name;
this.age=age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
class HashDemo1
{
public static void main(String[] args)
{
HashSet p=new HashSet();
p.add(new Person("lisi",21));
p.add(new Person("zhangsan",31));
p.add(new Person("wangwu",41));
p.add(new Person("maliu",51));
System.out.println(p);
Iterator it=p.iterator();
while(it.hasNext())
// System.out.println(it.next());
Person a=(Person)it.next();
System.out.println(a);
/* HashDemo1.java:39: 错误: 不是语句
Person a=(Person)it.next();
^
HashDemo1.java:39: 错误: 需要';'
Person a=(Person)it.next();
*/
System.out.println("Hello World!");
}
}
|
|