set循环遍历删除特定元素
public class Demo {
public static void main(String[] args) {
Set<Object> obj = new HashSet<Object>();
obj.add("a");
obj.add("b");
obj.add("c");
System.out.println("移除前:" + obj.toString());
Iterator<Object> it = obj.iterator();
for(int i=0; i<obj.size(); i++){
System.out.println(i);
Object name = it.next();
if("a".equals(name) || "b".equals(name)){
it.remove();
i--;
}
}
System.out.println("移除后: " + obj.toString());
}
}
作者:cchilei
-------------------------------------------
个性签名:竹杖芒鞋轻胜马 一蓑烟雨任平生
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!