Java Collection Union union(Collection coll)

Here you can find the source of union(Collection coll)

Description

Returns the union of all the sets given in a collection.

License

Open Source License

Parameter

Parameter Description
coll A Collection of sets

Declaration

public static Set union(Collection coll) 

Method Source Code


//package com.java2s;
//The MIT License

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Main {
    /**//  w  w  w . ja  v  a  2 s  .  c o m
     * Returns the union of all the sets given in a collection. 
     * 
     * @param coll A Collection of sets
     */
    public static Set union(Collection coll) {
        Set set = new HashSet();
        for (Iterator i = coll.iterator(); i.hasNext();) {
            set.addAll((Collection) i.next());
        }

        return set;
    }

    /**
     * Returns the union of two collections 
     * 
     * @param coll A Collection of sets
     */
    public static Set union(Collection c1, Collection c2) {
        Set set = new HashSet();
        set.addAll(c1);
        set.addAll(c2);

        return set;
    }
}

Related

  1. union(Collection c1, Collection c2)
  2. union(Collection collection1, Collection collection2)
  3. union(Collection c1, Collection c2)
  4. union(Collection> sets)
  5. union(Collection a, Collection b)