Here you can find the source of union(Collection
public static <T> List<T> union(Collection<T> c1, Collection<T> c2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { /**// w w w . jav a2 s.co m * intersection of c1 and c2, does not change input collections, returns new collection (list) */ public static <T> List<T> union(Collection<T> c1, Collection<T> c2) { if (c1 == null && c2 == null) { return Collections.emptyList(); } if (c1 == null) { return new ArrayList<>(c2); } if (c2 == null) { return new ArrayList<>(c1); } List<T> tmp = new ArrayList<>(c1.size() + c2.size()); tmp.addAll(c1); tmp.addAll(c2); return tmp; } public static <T> List<T> emptyList() { return Collections.emptyList(); } }