Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static <E> void intersection(final Collection<E> a, final Collection<E> b) { if (b != null && !b.isEmpty()) { if (a.isEmpty()) { a.addAll(b); } else { a.retainAll(b); } } } }