标签:div iter print equals cat ++ exce main exception
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); for (int i = 0; i < list.size(); i++) { list.remove(i); } System.out.println(list); }
输出:[b, d]
public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); for (String s : list) { if (s.equals("a")) list.remove(s); } }
报错ConcurrentModificationException
public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c", "d")); Iterator<String> iter = list.iterator(); while (iter.hasNext()) { String s = iter.next(); if (s.equals("a")) { iter.remove(); } }
}
输出:[b, c, d]
java操作数组转list集合删除元素报错ConcurrentModificationException
标签:div iter print equals cat ++ exce main exception
原文地址:https://www.cnblogs.com/bigsiji/p/12150500.html