Here you can find the source of intersection(final List extends T> list1, final List extends T> list2)
public static <T> List<T> intersection(final List<? extends T> list1, final List<? extends T> list2)
//package com.java2s; /*//from w ww . jav a 2 s . co m * Commons-Utils * Copyright (c) 2017. * * Licensed under the Apache License, Version 2.0 (the "License") */ import java.util.*; public class Main { public static <T> List<T> intersection(final List<? extends T> list1, final List<? extends T> list2) { List<? extends T> smaller = list1; List<? extends T> larger = list2; if (list1.size() > list2.size()) { smaller = list2; larger = list1; } List<T> newSmaller = new ArrayList<T>(smaller); List<T> result = new ArrayList<T>(smaller.size()); for (final T e : larger) { if (newSmaller.contains(e)) { result.add(e); newSmaller.remove(e); } } return result; } }