Java Set Intersect intersectTwoSets(Set a, Set b)

Here you can find the source of intersectTwoSets(Set a, Set b)

Description

intersect Two Sets

License

Open Source License

Declaration

private static <T> Set<T> intersectTwoSets(Set<T> a, Set<T> b) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    private static <T> Set<T> intersectTwoSets(Set<T> a, Set<T> b) {
        if (a == null || b == null)
            return new HashSet<>();
        Set<T> result = new HashSet<>(a);
        result.retainAll(b);/*from  w  w  w. j  a va 2 s  . c  o  m*/
        return result;
    }
}

Related

  1. intersection(Set setA, Set setB)
  2. intersectionP(Set s1, Set s2)
  3. intersects(Set set1, Set set2)
  4. intersectSet(Set orig, Set intersect)
  5. intersectsWith(final Set a, final Set b)