List intersection - Java Collection Framework

Java examples for Collection Framework:List

Description

List intersection

Demo Code


//package com.java2s;
import java.util.*;

public class Main {
    public static <T> List<T> intersection(List<T> list1, List<T> list2) {
        List<T> list = new ArrayList<T>();
        for (T t : list1) {
            if (list2.contains(t)) {
                list.add(t);/*w w w .j a va  2 s  .  c o  m*/
            }
        }
        return list;
    }
}

Related Tutorials