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); } } }
时间: 2024-10-05 16:22:13