Here you can find the source of intersect(Set one, Set two)
public static Set intersect(Set one, Set two)
//package com.java2s; // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main { /**/*from w ww.ja v a2 s . co m*/ * Form a new set that is the intersection of one set with another set. */ public static Set intersect(Set one, Set two) { HashSet n = new HashSet(one.size()); Iterator it = one.iterator(); while (it.hasNext()) { Object v = it.next(); if (two.contains(v)) { n.add(v); } } return n; } }