Java examples for java.util:List Duplicate Element
Removes the duplicates from List.
//package com.book2s; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; public class Main { public static void main(String[] argv) { List items = java.util.Arrays.asList("asdf", "book2s.com"); System.out.println(removeDuplicates(items)); }// ww w . j av a 2 s . c om /** * Removes the duplicates. * * @param <T> * the generic type * @param items * the items * @return the list */ public static <T> List<T> removeDuplicates(List<T> items) { Set<T> set = new LinkedHashSet<T>(); set.addAll(items); return new ArrayList<T>(set); } }