Java Set Intersect intersect(Set one, Set two)

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

Description

Form a new set that is the intersection of one set with another set.

License

Mozilla Public License

Declaration


public static Set intersect(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 ww.ja v  a2 s .  co m*/
     * Form a new set that is the intersection of one set with another set.
     */

    public static Set intersect(Set one, Set two) {
        HashSet n = new HashSet(one.size());
        Iterator it = one.iterator();
        while (it.hasNext()) {
            Object v = it.next();
            if (two.contains(v)) {
                n.add(v);
            }
        }
        return n;
    }
}

Related

  1. getIntersection(Set a, Set b)
  2. getIntersection(Set s1, Set s2)
  3. intersect(Collection set1, Collection set2)
  4. intersect(final Set firstSet, final Set secondSet)
  5. intersect(Set set1, Set set2)
  6. intersect(Set a, Set b)
  7. intersect(Set a, Set b)
  8. intersectComparable(Set left, Set right)