Iterator i1=h1.iterator();while(i1.hasNext()){int p=(int)(i1.next());}
Iterator i1=h1.iterator();
while(i1.hasNext()){
int p=(int)(i1.next());
}
请用python编程语言术语解释这段代码,这里h1是linkedhashset提前谢谢
pokxtpni1#
迭代“linkedhashset”有不同的方法,例如使用:“foreach”或“iterate”。迭代器是可用于迭代集合中所有元素的对象。迭代器有两个重要的方法(hasnext,next)。我对你的每一行代码都做了解释
Iterator i1 = h1.iterator(); //obtain an iterator of the collectionwhile(i1.hasNext()) { // Continue iterating because has a next element int p=(int)(i1.next()); //return the next element and parse it to "int"}
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"
还可以使用迭代器添加或删除元素。其他资源:java迭代器-geeks for geeksjava官方文档
1条答案
按热度按时间pokxtpni1#
迭代“linkedhashset”有不同的方法,例如使用:“foreach”或“iterate”。
迭代器是可用于迭代集合中所有元素的对象。迭代器有两个重要的方法(hasnext,next)。
我对你的每一行代码都做了解释
还可以使用迭代器添加或删除元素。
其他资源:
java迭代器-geeks for geeks
java官方文档