Java Set Union union(Set one, Set two)

Here you can find the source of union(Set one, Set two)

Description

Form a new set that is the union of two IntSets.

License

Mozilla Public License

Declaration


public static Set union(Set one, Set two) 

Method Source Code


//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;
    }
}

Related

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