Java Set Intersect intersectSet(Set orig, Set intersect)

Here you can find the source of intersectSet(Set orig, Set intersect)

Description

intersect Set

License

Open Source License

Parameter

Parameter Description
orig if null, return intersect

Declaration

public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect) 

Method Source Code


//package com.java2s;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Main {
    /**/*w  w w. j ava 2 s .  c o m*/
     * @param orig
     *            if null, return intersect
     */
    public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect) {
        if (orig == null)
            return intersect;
        if (intersect == null || orig.isEmpty())
            return Collections.emptySet();
        Set<Object> set = new HashSet<Object>(orig.size());
        for (Object p : orig) {
            if (intersect.contains(p))
                set.add(p);
        }
        return set;
    }
}

Related

  1. intersection(Set s1, Set s2)
  2. intersection(Set setA, Set setB)
  3. intersection(Set setA, Set setB)
  4. intersectionP(Set s1, Set s2)
  5. intersects(Set set1, Set set2)
  6. intersectsWith(final Set a, final Set b)
  7. intersectTwoSets(Set a, Set b)