Write code to get set Intersection - Java java.util

Java examples for java.util:Set Intersection

Requirements

Write code to set Intersection

Demo Code

//package com.java2s;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <A> Set<A> setIntersection(Set<A> a, Set<A> b) {
        Set<A> set = new HashSet<A>();
        for (A x : a)
            if (b.contains(x))
                set.add(x);//  ww  w.  j  a  v  a 2 s.  c o  m
        return set;
    }
}

Related Tutorials