Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Main {

    public static <T extends Comparator<T>> List<T> intersection(List<T> array1, List<T> array2) {
        if (isEmpty(array1) || isEmpty(array2)) {
            return null;
        }
        List<T> targets = new ArrayList<T>();
        for (T item : array1) {
            if (array2.contains(item)) {
                targets.add(item);
            }
        }
        return targets;
    }

    public static <T extends Comparator<T>> Boolean isEmpty(List<T> collection) {
        return collection == null || collection.isEmpty();
    }
}