Java tutorial
//package com.java2s; import java.util.*; public class Main { /** * Merge lists * @param first - List * @param second - List * @param <T> - Object class * @return - List */ public static <T> List<T> mergeLists(List<T> first, List<T> second) { Map<T, T> dataMap = listToMap(first); for (T object : second) { dataMap.put(object, object); } List<T> resultObject = new LinkedList<T>(); for (T object : dataMap.keySet()) { resultObject.add(object); } return resultObject; } /** * Load a list to a map * @param input - List * @param <V> - Object class * @return - Map */ public static <V> Map<V, V> listToMap(List<V> input) { Map<V, V> dataMap = new HashMap<V, V>(); for (V object : input) { dataMap.put(object, object); } return dataMap; } }