Java tutorial
//package com.java2s; import java.util.ArrayList; public class Main { public static ArrayList<Integer> intersection(ArrayList<Integer> arrayList1, ArrayList<Integer> arrayList2) { ArrayList<Integer> intersectionList = new ArrayList<Integer>( arrayList1.size() > arrayList2.size() ? arrayList1.size() : arrayList2.size()); intersectionList.addAll(arrayList1); intersectionList.retainAll(arrayList2); return intersectionList; } }