ArrayList能用Collections.sort()进行排序,但CopyOnWriteArrayList不能用Collections.sort()进行排序
原因:
CopyOnWriteArrayList没有set(),
而ArrayList则支持set方法
public E set(int index,E element)
?
如果需要使用Collections.sort(),要么用线程不安全的ArrayList,要么如以下网址所示自己处理
?
?
Sorting a CopyOnWriteArrayList
http://www.javacreed.com/sorting-a-copyonwritearraylist/
?
Sorting a CopyOnWriteArrayList
http://stackoverflow.com/questions/25390782/sorting-a-copyonwritearraylist
I cannot use Collections.sort() for CopyOnWriteArrayList as it doesn't support the set() operation.