Here you can find the source of intersection(List
public static int intersection(List<String> list1, List<String> list2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static int intersection(List<String> list1, List<String> list2) { List<String> intersection = new ArrayList<String>(); for (String s : list1) { if (list2.contains(s)) { intersection.add(s);//from w w w. j a va 2 s . co m } } return intersection.size(); } }