Here you can find the source of intersection(Set
static public <T> Set<T> intersection(Set<T> s1, Set<T> s2)
//package com.java2s; import java.util.*; public class Main { static public <T> Set<T> intersection(Set<T> s1, Set<T> s2) { Set<T> s3 = new HashSet<T>(s1); s3.retainAll(s2);//from w w w . j a v a2s . c o m return s3; } }