移除集合中指定条件的元素

01 	    /**
02 	     * <p>
03 	     * removeEFromList方法-移除集合中指定条件的元素.
04 	     * </p>
05 	     * <p>
06 	     * 创建人 IT山人 创建时间 2011-4-29 - 下午12:27:44
07 	     * </p>
08 	     * @return List<String> 移除元素后的集合
09 	     */
10 	    public static List<String> removeEFromList() {
11 	        List<String> stringList = getTestStringList();
12 	        // 方法一
13 	//      List<String> string2List = new ArrayList<String>();
14 	//      for (String string : stringList) {
15 	//          if (!"需要移除的数据".equals(string)) {
16 	//              string2List.add(string);
17 	//          }
18 	//      }
19 	//      stringList = string2List;
20 	         
21 	        // 方法二
22 	        Iterator<String> strIterator = stringList.iterator();
23 	        while (strIterator.hasNext()) {
24 	            String string = (String) strIterator.next();
25 	            if ("需要移除的数据".equals(string)) {
26 	                strIterator.remove();
27 	            }
28 	        }
29 	         
30 	        return stringList;
31 	    }

转载于:https://my.oschina.net/u/140625/blog/59282

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值