将 CopyOnWriteArrayList 复制到经典的 ArrayList,如何?

Copying CopyOnWriteArrayList to classic ArrayList, how?

已经尝试过正常赋值并且:

Collections.copy(lostPackets, historyList);

抛出:

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

有什么方法可以将 COWArrayList 复制到普通的 ArrayList 吗?

给你

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

lostPackets.addAll(historyList);

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