Example usage for java.util.concurrent CopyOnWriteArrayList toArray

List of usage examples for java.util.concurrent CopyOnWriteArrayList toArray

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList toArray.

Prototype

public Object[] toArray() 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Usage

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]);
    }
}