Here you can find the source of calcIntersection(List
public static void calcIntersection(List<Integer> a, List<Integer> b)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static void calcIntersection(List<Integer> a, List<Integer> b) { int aBegin = 0; int bBegin = 0; while (aBegin < a.size()) { while (bBegin < b.size() && b.get(bBegin).intValue() < a.get(aBegin).intValue()) { bBegin++;//from ww w . j av a 2 s .c o m } if (bBegin < b.size() && a.get(aBegin).intValue() == b.get(bBegin).intValue()) { aBegin++; } else { a.remove(aBegin); } } } }