将CopyOnWriteArrayList复制到经典ArrayList,怎么做?

时间:2015-12-28 00:36:46

标签: java arraylist copyonwritearraylist

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

Collections.copy(lostPackets, historyList);

抛出:

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

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

2 个答案:

答案 0 :(得分:2)

- (void)updateUserActivityState:(NSUserActivity *)userActivity { [userActivity addUserInfoEntriesFromDictionary:@{@"id" : _displayedPerson.personID, @"fullName" : [_displayedPerson completeName]}]; }

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

答案 1 :(得分:0)

你去吧

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