1

已经尝试过正常分配并且:

Collections.copy(lostPackets, historyList);

抛出:

Exception in thread "Thread-3" java.lang.IndexOutOfBoundsException: Source does not fit in dest

有没有办法将 COWArrayList 复制到普通的 ArrayList 中?

4

2 回答 2

3

lostPackets.addAll(historyList);

请注意,如果您只想保留最近的记录,CopyOnWriteArrayList请先清除ArrayListusingclear()方法,然后使用addAll().

于 2015-12-28T00:49:08.960 回答
0

干得好

列表 arrayList = Arrays.asList(cowArrayList.toArray());

于 2015-12-28T00:40:43.797 回答