Here you can find the source of unionList(List
public static <T> List<T> unionList(List<T> la, List<T> lb)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static <T> List<T> unionList(List<T> la, List<T> lb) { if (la == null) { la = new ArrayList<T>(); }/*ww w. java 2 s. c o m*/ if (lb == null) { lb = new ArrayList<T>(); } List<T> cpLa = new ArrayList<T>(); List<T> cpLb = new ArrayList<T>(); cpLa.addAll(la); cpLb.addAll(lb); List<T> dumpList = new ArrayList<T>(); for (T t : cpLa) { if (cpLb.contains(t)) { dumpList.add(t); } } cpLa.removeAll(dumpList); cpLb.removeAll(dumpList); cpLa.addAll(cpLb); return cpLa; } }