python中的LinkedHashSet替代方案


Iterator i1=h1.iterator();
while(i1.hasNext()){
int p=(int)(i1.next());
}

请用python编程语言术语解释这段代码,这里h1是linkedhashset提前感谢

您有不同的方法来迭代一个"LinkedHashSet";,例如使用:";对于每个";或";迭代";。

迭代器是一个对象,可以用来迭代集合中的所有元素。Iterator有两个重要的方法(hasNext,next(。

我对你的代码的每一行都做了解释

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 Iterator-Geeks for Geeks

Java官方文档

最新更新