Here you can find the source of union(Collection
public static <T> Set<T> union(Collection<T> lhs, Collection<T> rhs)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static <T> Set<T> union(Collection<T> lhs, Collection<T> rhs) { HashSet<T> results = new HashSet<>(lhs.size() + rhs.size()); results.addAll(lhs);/* ww w . j a va2 s . co m*/ results.addAll(rhs); return results; } }