移除list里面的值

public class IteratorTest {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String test = iterator.next();
            if ("aaa".equals(test)) {
                iterator.remove();
            }
        }
        for (String s: list) {
            System.out.print(s);
        }
    }
}

  

posted @ 2017-03-10 14:24  growthofmonkey  阅读(419)  评论(0编辑  收藏  举报