Here you can find the source of union(ArrayList
public static <T> ArrayList<T> union(ArrayList<T> a, ArrayList<T> b)
//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; } }