List 循环删除 指定元素的 方法

使用Iterator进行循环,在删除指定元素。
如果使用for 或 foreach 在删除指定下标是,list.size 会相应的缩短且下标前移,导致相邻满足条件的元素未删除




Iterator<String> it = list.iterator(); while(it.hasNext()){ String x = it.next(); if(x.equals("del")){ it.remove(); } }
posted @ 2019-04-04 17:05  MisMe  阅读(1413)  评论(0编辑  收藏  举报