Here you can find the source of distinctList(List
public static <V> int distinctList(List<V> sourceList)
//package com.java2s; /**/*w w w. j ava2 s . co m*/ * Copyright (c) 2014 http://www.lushapp.wang * * Licensed under the Apache License, Version 2.0 (the "License"); */ import java.util.List; public class Main { public static <V> int distinctList(List<V> sourceList) { if (isEmpty(sourceList)) { return 0; } int sourceCount = sourceList.size(); int sourceListSize = sourceList.size(); for (int i = 0; i < sourceListSize; i++) for (int j = (i + 1); j < sourceListSize; j++) { if (sourceList.get(i).equals(sourceList.get(j))) { sourceList.remove(j); sourceListSize = sourceList.size(); j--; } } return sourceCount - sourceList.size(); } public static boolean isEmpty(List<?> sourceList) { return (sourceList == null || sourceList.size() == 0); } }