Here you can find the source of unique(List
public static <T extends Comparable<? super T>> List<T> unique(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static <T extends Comparable<? super T>> List<T> unique(List<T> list) { if (list.size() < 2) { return list; }/*from w w w . ja v a 2 s .c o m*/ List<T> sorted = new LinkedList<T>(list); Collections.sort(sorted); T current = sorted.get(sorted.size() - 1); for (int i = sorted.size() - 1; i > 0; i--) { T previous = sorted.get(i - 1); if (current == null || current.compareTo(previous) == 0) { sorted.remove(i); } current = previous; } if (sorted.get(0) == null) { sorted.remove(0); } return sorted; } }