Java List Distinct Value distinctList(List sourceList)

Here you can find the source of distinctList(List sourceList)

Description

distinct List

License

Apache License

Declaration

public static <V> int distinctList(List<V> sourceList) 

Method Source Code

//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);
    }
}

Related

  1. addWithExpDecay(List distinctVals)
  2. constructDistinctClause(StringBuffer selectClause, List attributes, boolean isCountOnly)
  3. distinct(List list)
  4. distinct(List list)
  5. distinct(List vector)
  6. getDistinctStrings(String[] list)
  7. sortedDistinct(List seq)