Java tutorial
//package com.java2s; //License from project: LGPL import java.util.HashSet; import java.util.Set; public class Main { public static Set<Integer> getIntersection(Set<Integer> set1, Set<Integer> set2) { Set<Integer> ret = new HashSet<Integer>(); for (Integer i : set1) { if (set2.contains(i)) { ret.add(i); } } return ret; } }