/** * @author lautturi.com * Java example: how to delete/remove duplicate elements from list in java */ import java.util.*; public class Lautturi { public static void main(String[] args) { List<Integer> list = new ArrayList(Arrays.asList(11,4,2,7,55,4,11,8,7,55)); System.out.println(list); Set<Integer> hashSet = new LinkedHashSet(list); List<Integer> newList = new ArrayList(hashSet); System.out.println(newList); } }
output:
[11, 4, 2, 7, 55, 4, 11, 8, 7, 55] [11, 4, 2, 7, 55, 8]