I want to sort CopyOnWriteArrayList. But when I tried to run the following code
CopyOnWriteArrayList
It is throwing unsorted operation exception.
unsorted operation exception
In JDK1.8 can use sort(Comparator super E> c) directly.
sort(Comparator super E> c)
List list = new CopyOnWriteArrayList(); list.add(3); list.add(4); list.add(1); list.sort(new Comparator() { @Override public int compare(Integer o1, Integer o2) { return o1 - o2; } });