<分区>
我有非常简单的代码:
List<String> list = new ArrayList<String>();
String a = "a";
String b = "b";
String c = "c";
String d = "d";
list.add(a);
list.add(b);
list.add(c);
List<String> backedList = list.subList(0, 2);
list.add(0, d);
System.out.println("2b: " + backedList);
我通过 list.add(0, d) 得到了 ConcurrentModificationException 异常。所以一般来说,是因为sublist()。我很困惑,因为在 sublist() 的情况下,文档说:
The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.
你能解释一下问题在哪里吗?