Here you can find the source of union(Set
Parameter | Description |
---|---|
sets | Multiple sets which will be united. |
T | Type of values. |
@SafeVarargs public static <T> Set<T> union(Set<T>... sets)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/* ww w .j a v a2 s . c o m*/ * Returns the union of multiple sets. * <p> * The original sets are not altered. * * @param sets Multiple sets which will be united. * @param <T> Type of values. * @return A set forming the union of the given sets. */ @SafeVarargs public static <T> Set<T> union(Set<T>... sets) { if (sets == null) return new HashSet<>(); Set<T> result = new HashSet<>(); for (Set<T> s : sets) { if (s != null) result.addAll(s); } return result; } }