Java tutorial
//package com.java2s; import java.util.HashSet; import java.util.List; public class Main { public static <T> List<T> mergeLists(List<T> oldList, List<T> newList) { //TreeSet setBoth = new TreeSet(newList); HashSet<T> setBoth = new HashSet<>(newList); setBoth.addAll(oldList); oldList.clear(); oldList.addAll(setBoth); return oldList; } }