我是靠谱客的博主 虚幻鸡翅,这篇文章主要介绍java iterator转_错误java.util.iterator无法转换为Iterator,第8行报错,为什么?,现在分享给大家,希望可以做个参考。

展开全部

你的程序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;

}

}

最后

以上就是虚幻鸡翅最近收集整理的关于java iterator转_错误java.util.iterator无法转换为Iterator,第8行报错,为什么?的全部内容,更多相关java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(124)

评论列表共有 0 条评论

立即
投稿
返回
顶部