List of usage examples for java.util.concurrent CopyOnWriteArrayList toArray
public Object[] toArray()
From source file:Main.java
/** * Sort the CopyOnWriteArrayList.//from w ww . jav a 2 s . com * * @param list The list to sort. * @param <E> The type of data. */ public static <E extends Comparable<E>> void sort(CopyOnWriteArrayList<E> list) { Object[] content = list.toArray(); Arrays.sort(content); for (int i = 0; i < content.length; i++) { list.set(i, (E) content[i]); } }
From source file:Main.java
/** * Sort the CopyOnWriteArrayList using the given comparator. * * @param list The list to sort./*from ww w. j a v a 2s . com*/ * @param comparator The comparator to use. * @param <E> The type of data. */ public static <E> void sort(CopyOnWriteArrayList<E> list, Comparator<E> comparator) { Object[] content = list.toArray(); Arrays.sort(content, (Comparator) comparator); for (int i = 0; i < content.length; i++) { list.set(i, (E) content[i]); } }