![图片[1]-python如何遍历set-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5dc37f8c990b4530.jpg)
1、利用迭代器进行迭代遍历:
Set<Object>sets=newHashSet<Object>();
Iterator<Object>it=set.iterator();
while(it.hasNext()){
Stringstr=(String)it.next();
System.out.println(str);
}
2、for循环遍历:
for(Stringstr:sets){
System.out.println(str);
}
3、foreach循环遍历:
Set<Object>set=newHashSet<Object>();
for(Objectobj:sets){
if(objinstanceofInteger){
intaa=(Integer)obj;
}elseif(objinstanceofString){
Stringaa=(String)obj
}
……..
}原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容