python如何遍历set

图片[1]-python如何遍历set-uusu优素-乐高,模型,3d打印,编程

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
喜欢就支持一下吧
点赞14 分享