Iterator i1=h1.iterator();
while(i1.hasNext()){
int p=(int)(i1.next());
}
请用python编程语言术语解释这段代码,这里的h1是linkedhashset 提前致谢
答案 0 :(得分:1)
您使用有不同的方式来迭代“LinkedHashSet”,例如:“的forEach”或“迭代”
迭代器是可用于进行迭代的集合中的所有元素的对象。迭代器有两个重要的方法(hasNext,下一个)。
我对你的每一行代码进行了解释
Iterator i1 = h1.iterator(); //obtain an iterator of the collection
while(i1.hasNext()) { // Continue iterating because has a next element
int p=(int)(i1.next()); //return the next element and parse it to "int"
}
还与一个Iterator可以添加或删除元素
其他资源:强>