Returns the union of two Integer lists. - Android java.lang

Android examples for java.lang:Math

Description

Returns the union of two Integer lists.

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
    /**//  w ww . j  a v a 2s.  c  om
     * Returns the union of two Integer lists.
     * @param A
     * @param B
     * @return
     */
    public static <T> List<T> union(List<T> A, List<T> B) {
        Set<T> set = new HashSet<T>();

        set.addAll(A);
        set.addAll(B);

        return new ArrayList<T>(set);
    }
}

Related Tutorials