Here you can find the source of union(Set one, Set two)
public static Set union(Set one, Set two)
//package com.java2s; // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main { /**//from w w w .j a va 2s.com * Form a new set that is the union of two IntSets. */ public static Set union(Set one, Set two) { HashSet n = new HashSet(one.size() + two.size()); Iterator it = one.iterator(); while (it.hasNext()) { n.add(it.next()); } it = two.iterator(); while (it.hasNext()) { n.add(it.next()); } return n; } }