intersect Set - Android java.util

Android examples for java.util:Set

Description

intersect Set

Demo Code


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

public class Main {
    /**// w  ww  .  j  a va2 s.c  om
     * @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 Tutorials