Java Set Union union(final Set... elements)

Here you can find the source of union(final Set... elements)

Description

union

License

Open Source License

Declaration

public static <T> Set<T> union(final Set<T>... elements) 

Method Source Code

//package com.java2s;
/*//from   w  w w . ja v  a 2  s.c o  m
 * Copyright (C) 2013
 *
 * 52?North Initiative for Geospatial Open Source Software GmbH
 * Contact: Andreas Wytzisk
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.Collections;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <T> Set<T> union(final Set<T>... elements) {
        return ((elements.length == 0) ? Collections.<T>emptySet()
                : new HashSet<T>(elements.length * elements[0].size()) {
                    private static final long serialVersionUID = -3161916411604210423L;
                    {
                        for (final Set<T> s : elements) {
                            addAll(s);
                        }
                    }
                });
    }
}

Related

  1. union(final Iterable> elements)
  2. union(final Set set1, final Set set2)
  3. union(Set one, Set two)
  4. union(Set a, Set b)
  5. union(Set left, Set right)
  6. union(Set setA, Set setB)