Java ArrayList Union Union(ArrayList list1, ArrayList list2)

Here you can find the source of Union(ArrayList list1, ArrayList list2)

Description

Finds the union of two lists of String objects

License

Open Source License

Parameter

Parameter Description
list1 First list
list2 Second list

Return

Union list (contains values that exist in either list)

Declaration

public static ArrayList<String> Union(ArrayList<String> list1, ArrayList<String> list2) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.util.*;

public class Main {
    /** Finds the union of two lists of String objects
     *// w w w  .j  av a  2  s  .  c om
     * @param list1 First list
     * @param list2 Second list
     * @return Union list (contains values that exist in either list)
     */
    public static ArrayList<String> Union(ArrayList<String> list1, ArrayList<String> list2) {
        Set union = new HashSet(list1);
        union.addAll(new HashSet(list2));
        return new ArrayList(union);
    }
}

Related

  1. union(ArrayList list1, ArrayList list2)
  2. union(ArrayList a, ArrayList b)
  3. unionSets(ArrayList s1, ArrayList s2)