Here you can find the source of mergeListNoDuplicate(List
public static <T> List<T> mergeListNoDuplicate(List<T> one, List<T> two)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static <T> List<T> mergeListNoDuplicate(List<T> one, List<T> two) { if (isAllNull(one, two)) return null; List<T> result = new ArrayList<>(); if (isAllNotNull(one, two)) { result.addAll(one);//from www. j a va 2 s.co m for (T t : two) { if (one.indexOf(t) == -1) { result.add(t); } } } else { result.addAll(findFirstNotNull(one, two)); } return result; } public static <T> boolean isAllNull(T one, T two) { return one == null ? two == null : false; } public static <T> boolean isAllNotNull(T one, T two) { return one != null && two != null; } public static <T> int indexOf(int start, List<T> datas, T target) { int index = -1; for (int i = start; i < datas.size(); i++) { if (datas.get(i).equals(target)) { index = i; break; } } return index; } public static <T> T findFirstNotNull(T... types) { for (T type : types) { if (type != null) return type; } return null; } }