set循环遍历删除特定元素
使用Iterator迭代器
- 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());
- }
- }
set循环遍历删除特定元素的更多相关文章
- Java集合类ArrayList循环中删除特定元素
在项目开发中,我们可能往往需要动态的删除ArrayList中的一些元素. 一种错误的方式: <pre name="code" class="java"&g ...
- 如何python循环中删除字典元素
//下面这行就是在循环中遍历删除字典元素的方法! for i in list(dictheme2.keys()): if dictheme2[i]<self.countFortheme: dic ...
- java 在循环中删除数组元素
在写代码中经常会遇到需要在数组循环中删除数组元素的情况,但删除会导致数组长度变化. package com.fortunedr.thirdReport; import java.util.ArrayL ...
- java集合遍历删除指定元素异常分析总结
在使用集合的过程中,我们经常会有遍历集合元素,删除指定的元素的需求,而对于这种需求我们往往使用会犯些小错误,导致程序抛异常或者与预期结果不对,本人很早之前就遇到过这个坑,当时没注意总结,结果前段时间又 ...
- STL——遍历 删除 set 元素
==================================声明================================== 本文版权归作者所有. 本文原创,转载必须在正文中显要地注明 ...
- map循环遍历删除
typedef map<string,int> MapFileList; int main() { MapFileList m_SingleList; m_SingleList.inser ...
- Java 循环遍历删除set list中的元素
删除List和Set中的某些元素 错误代码的写法: Set<String> set = new HashSet<String>(); set.add("aaaaaa& ...
- ArrayList删除特定元素的方法
最朴实的方法,使用下标的方式: ArrayList<String> al = new ArrayList<String>(); al.add("a"); a ...
- vector删除特定元素
删除vector中小于20的元素,注意要使迭代器失效,不能简单的删除. #include <iostream>#include <vector>using namespace ...
随机推荐
- sql server auto increment - trace flag 272
从 sql 2012 开始, 微软为了让 insert 时 auto increment 快一些,做了一个 cache 的机制. 这个机制虽然好,但是也有麻烦的情况,如果你的 sql 突然 resta ...
- appium --log-timestamp > appium.log
appium --log-timestamp > appium.log
- 编写脚本,出现 TypeError: exceptions must be old-style classes or derived from BaseException, not unicode怎样解决?
小编使用robot framework,在编写安卓自动化脚本时,出现这样的情况: 在网上搜了好久,发现都是python的解决方法,到底怎样解决robot里面的问题呢?最终发现: (1)代码中我是这样写 ...
- SublimeText3按ctrl+b执行python无反应
现象:在Sublime中打开.py文件,按”ctrl+b”执行时无反应.点击工具->编译系统中已经有且识别到Python,但执行”run(ctrl+shift+b)”时无反应,Sublime左下 ...
- stm32cube使用
1.使用stm32cube生成CAN代码注意事项: a.需要手动配置CAN过滤器 { CAN_FilterConfTypeDef sFilterConfig; uint32_t filterID = ...
- MySQL Server and Server-Startup Programs
1. mysqld-The MySQL Server mysqld,also known as mysql server, is the main program that does most of ...
- Java Config for WebProject
1.Java EE vs Java SE They are just official SDK,when using IDE,it's ok to just install jdk/jre. &quo ...
- spring cloud: zuul: 微网关-简单使用与路由配置
spring cloud: zuul: 微网关-简单使用与路由配置 首先引入依赖 <dependency> <groupId>org.springframework.cloud ...
- Python实现Plugin(插件化开发)
https://www.cnblogs.com/terencezhou/p/10276167.html
- unitest 测试集 实例
-->baidy.py #coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.by import B ...