Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { @SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection in(Collection source, Collection target) { if (source == null || source.size() == 0) { return null; } if (target == null || target.size() == 0) { return null; } Collection result = new ArrayList(); for (Iterator it = source.iterator(); it.hasNext();) { Object candidate = it.next(); if (target.contains(candidate)) { result.add(candidate); } } return result; } }