Here you can find the source of union(final Set
public static <T> Set<T> union(final Set<T>... elements)
//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); } } }); } }