gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:07:07 26 4
gpt4 key购买 nike

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

Collections.copy(lostPackets, historyList);

抛出:

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

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

最佳答案

lostPackets.addAll(historyList);

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

关于java - 将 CopyOnWriteArrayList 复制到经典 ArrayList,如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34486371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com