intersection Set - Java Collection Framework

Java examples for Collection Framework:Set

Description

intersection Set

Demo Code


//package com.java2s;
import java.util.HashSet;
import java.util.Iterator;

public class Main {

    public static HashSet<String> intersectionSet(HashSet<String> setA,
            HashSet<String> setB) {
        HashSet<String> intersectionSet = new HashSet<String>();
        Iterator<String> iterA = setA.iterator();
        while (iterA.hasNext()) {
            String tempInner = iterA.next();
            if (setB.contains(tempInner)) {
                intersectionSet.add(tempInner);
            }//from  w ww.  j a  va 2  s  .  c  o  m
        }
        return intersectionSet;
    }
}

Related Tutorials