- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经定义了 ArrayList:
ArrayList<String> numbers = new ArrayList<String>();
我只想处理它的特定部分,所以我创建了子列表:
List<String> numbersh = numbers.subList(o, p + 1);
我了解一个基本概念并且它对我有用,直到我意识到需要自己使用 ArrayList:
numbers.remove(p + 1);
在我尝试再次使用 subList 之前它可以正常工作:
numbersh.remove(0);
我收到/from AbstractList.class/:
throw new ConcurrentModificationException();
为了更好地理解想象以下 ArrayList/numbers/:
[1,2,3,4,5,6,7,8]/数字/
及其 List<String> numbersh = numbersh.subList(3, 5);
由 [4,5,6] 组成
我正在做的是 numbers.remove(6);
这超出了 subList 范围,应该导致
[1,2,3,4,5,6,8]/数字/
然后我尝试 numbersh.remove(0)
这应该导致:
[1,2,3,5,6,8]/数字/
我有点迷茫了。有什么想法吗?
最佳答案
您忘记了 subList() 确实不返回新列表,而只是原始列表的一部分。
public List<E> subList(int fromIndex, int toIndex) {
subListRangeCheck(fromIndex, toIndex, size);
return new SubList(this, 0, fromIndex, toIndex);
}
SubList(AbstractList<E> parent,
int offset, int fromIndex, int toIndex) {
this.parent = parent;
this.parentOffset = fromIndex;
this.offset = offset + fromIndex;
this.size = toIndex - fromIndex;
this.modCount = ArrayList.this.modCount;
}
如果您需要单独修改和访问 List 和 subList,您将需要创建原始 List 的深拷贝。
关于Java subList ConcurrentModificationException();,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25159552/
谁能解释为什么 subList() 不像 subSet() 方法那样运行,并抛出 ConcurrentModificationException,而 子集 不是。这两种方法都创建了一个 Backed
是否有任何函数或方法可以在 python 2.7 中递归实现此目的? Input : ['and', ['or', 'P', '-R', 'P'], ['or', '-Q', '-R', 'P']]
让我们考虑一下:List ints = Arrays.asList("1","2","3","4","5","6")让 k=2 . 我们想返回以下列表 List : ["12", "23", "34
当我使用子列表时,我遇到了 ConcurrentModificationException 问题。 我的问题是:使用子列表创建新集合是否安全? 示例: List list = new LinkedLi
如果有重复,我深表歉意,但我进行了搜索,但找不到任何可以解决我当前问题的主题。 我想知道是否有某种Pythonic方法可以并行迭代两个(或更多)子列表。我已经很了解 zip 函数,因此我将在一个简短的
我已经定义了 ArrayList: ArrayList numbers = new ArrayList(); 我只想处理它的特定部分,所以我创建了子列表: List numbersh = number
public List> splitList( List values) { List> newList = new ArrayList>(); //Type mism
我有一个显示 Glassfish 日志文件列表的 JSF 页面。我使用延迟加载进行分页。我将日志文件名列表保存到 Java List. private List dataList = new Arra
是否有技巧或前奏函数来测试列表是否包含特定的子字符串/子列表? xyz :: [a] -> [a] -> Bool xyz "hello world" "worl" -> True xyz [1,2,
我在单元测试中遇到了这个问题。 执行后: List cleanCards = cards.subList(0, cards.size() - difference); 以下断言给了我一个 Concur
我需要实现一个在序列上滑动的滑动窗口。 (1:[0,1,2,3]2:[1,2,3,4],...)哪个批准可能更快?1. for each step i; {List=wholeList.sublist
因此我修改了 API(用于命令管理)以使用 String[] 而不是字符串列表。 我的问题在这里:strings.subList(1, strings.length)所以我需要将其更改为可以完成相同工
如果我有一个变量 LinkedList list 并重复执行以下操作以提取“列表”的尾部 // Some operation that adds elements to 'list' // max_s
我很想知道最新的 JVM 如何处理通过以下方法保留的垃圾回收内存。 public List getHallOfFame() { ArrayList listToSort = new ArrayLi
我有一个使用 JPA 保存的 java 对象。该对象有一个成员“friendsList”,它是一个字符串列表。我在这个对象上使用了@CollectionOfElements hibernate 注释。
我有一个长度为 x 值的列表。该列表被分解成不同长度的子列表。然后我将这些子列表写入输出文件。有没有办法打印没有括号的子列表。 编辑清楚: 实际 列表有 300 个子列表,其中包含 12250 个元素
Erlang 有没有办法在 ets 表上创建一个选择查询,它将获得 的所有元素包含 搜索到的文本? ets:select(Table, [{ %% Match spec for select qu
这是简化的代码 public Page getTestData(TestData testData, Pageable pageRequest) { List results = getSomethi
我是序言的新学习者。这是我们工作室的问题,我不知道从哪里开始。 真的很感激这方面的任何帮助。 子列表(Xs,Ys) 当 Xs 是一个包含 Ys 的某些元素的列表时,这适用于它们在列表 Ys 中出现的相
我目前正在开发我的第一个 Android 应用程序。它解析 JSON 数据并将其放入 ListView(见下文)。 protected void onPostExecute(String result
我是一名优秀的程序员,十分优秀!