Collections.sort uses ListIterator.set
...
for (int j=0; j<a.length; j++) {
i.next();
i.set((T)a[j]);
}
but CopyOnWriteArrayList's ListIterator does not support the remove, set or add methods.
Workaround:
Object[] a = list.toArray();
Arrays.sort(a);
for (int i = 0; i < a.length; i++) {
list.set(i, (String) a[i]);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…