Java ArrayList Union union(ArrayList a, ArrayList b)

Here you can find the source of union(ArrayList a, ArrayList b)

Description

union

License

Open Source License

Declaration

public static <T> ArrayList<T> union(ArrayList<T> a, ArrayList<T> b) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    public static <T> ArrayList<T> union(ArrayList<T> a, ArrayList<T> b) {
        ArrayList<T> result = new ArrayList<T>();

        for (T t : a)
            if (!result.contains(t))
                result.add(t);/*from w  ww  .  jav a2 s  . c  o m*/
        for (T t : b)
            if (!result.contains(t))
                result.add(t);

        return result;
    }
}

Related

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