Java List Distinct Value addDistinctEntry(List sourceList, V entry)

Here you can find the source of addDistinctEntry(List sourceList, V entry)

Description

add distinct entry to list

License

Apache License

Parameter

Parameter Description
V a parameter
sourceList a parameter
entry a parameter

Return

if entry already exist in sourceList, return false, else add it and return true.

Declaration

public static <V> boolean addDistinctEntry(List<V> sourceList, V entry) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {
    /**// w w  w. ja va 2 s  . co  m
     * add distinct entry to list
     * 
     * @param <V>
     * @param sourceList
     * @param entry
     * @return if entry already exist in sourceList, return false, else add it and return true.
     */
    public static <V> boolean addDistinctEntry(List<V> sourceList, V entry) {
        return (sourceList != null && !sourceList.contains(entry)) ? sourceList.add(entry) : false;
    }
}

Related

  1. addDistinctItems(List fromItems, List toItems)
  2. addDistinctList(List sourceList, List entryList)
  3. addWithExpDecay(List distinctVals)
  4. constructDistinctClause(StringBuffer selectClause, List attributes, boolean isCountOnly)