展开全部
你的程序62616964757a686964616fe59b9ee7ad9431333337393033有点小问题:类名不能是Iterator,与jdk自带的类名重名了
2. next()这样写
3. 注释的话,应该用//,而不是\\
修改过的代码如下:import java.util.*;
public class ShowDemo{
public static void main(String[] args){
Collection c=new HashSet();
c.add(new Name("f1","l1"));
c.add(new Name("f2","l2"));
c.add(new Name("f3","l3"));
Iterator i = c.iterator();//报错
while(i.hasNext()){
Name n = (Name)i.next();
System.out.print(n.getFirst()+" ");
}
}
}
class Name{
String first,last;
Name(String first,String last){
this.first = first;
this.last = last;
}
public String getFirst(){
return first;
}
public String getLast(){
return last;
}
}