Iterator i1=h1.iterator();
while(i1.hasNext()){
int p=(int)(i1.next());
}
请用python编程语言术语解释此代码,这里h1是linkedhashset预先感谢
您有不同的方法来迭代“ LinkedHashSet”,例如,使用:“ forEach”或“ iterate”。
迭代器是一个对象,可用于迭代集合中的所有元素。迭代器有两个重要的方法(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"
}
此外,还可以使用Iterator添加或删除元素。
其他资源:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句