Example usage for java.util.concurrent CopyOnWriteArrayList set

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

Introduction

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

Prototype

public E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this list with the specified element.

Usage

From source file:Main.java

/**
 * Sort the CopyOnWriteArrayList.// www  . j  a v  a  2  s.c om
 *
 * @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  av  a  2  s.  c o  m*/
 * @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]);
    }
}