Here you can find the source of intersection(List
public static <T> List<T> intersection(List<T> listOne, List<T> listTwo)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static <T> List<T> intersection(List<T> listOne, List<T> listTwo) { ArrayList<T> onlyInOne = new ArrayList<T>(listOne); onlyInOne.removeAll(listTwo);/*from ww w.j a v a2 s . c om*/ ArrayList<T> inBoth = new ArrayList<T>(listOne); inBoth.removeAll(onlyInOne); return inBoth; } }