Example usage for java.util.concurrent CopyOnWriteArraySet addAll

List of usage examples for java.util.concurrent CopyOnWriteArraySet addAll

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArraySet addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present.

Usage

From source file:Main.java

/**
 * This method, as the name suggests, will take the union of all the input sets,
 * creating an output, thread-safe set./*  w w  w  .j a  va 2  s . c o  m*/
 * @param collections    input sets
 * @param <E>     type of set items
 * @return a set that is the union of all input sets
 */
public static <E> Set<E> union(Collection<E>... collections) {
    final CopyOnWriteArraySet<E> result = new CopyOnWriteArraySet<E>();
    for (Collection<E> collection : collections) {
        result.addAll(collection);
    }
    return result;
}