bangalore

ConcurrentModificationException thrown by sublist

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have very simple code: List list = new ArrayList (); String a = "a"; String b = "b"; String c = "c"; String d = "d"; list.add(a); list.add(b); list.add(c); List backedList = list.subList(0, 2); list.add(0, d); System.out.println("2b: " + backedList); And I get ConcurrentModificationException exception by list.add(0, d). So in general, it's because of sublist(). I'm very confused, because in case of sublist() the documentation says: The returned list is backed by this list, so non-structural changes in the returned list are reflected in