Java Set Intersect intersect(Set a, Set b)

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

Description

intersect

License

Open Source License

Declaration

public static <E> Set<E> intersect(Set<E> a, Set<E> b) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static <E> Set<E> intersect(Set<E> a, Set<E> b) {
        Set<E> intersect = new HashSet<>();
        for (E entryA : a) {
            if (b.contains(entryA)) {
                intersect.add(entryA);//  ww  w  .  j a v  a 2s. c om
            }
        }
        for (E entryB : b) {
            if (a.contains(entryB)) {
                intersect.add(entryB);
            }
        }
        return intersect;
    }
}

Related

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