Android examples for java.util:List Element
add all distinct entry to list1 from list2
//package com.java2s; import java.util.List; public class Main { /**/*www . j av a 2 s . c o m*/ * add all distinct entry to list1 from list2 * * @param <V> * @param sourceList * @param entryList * @return the count of entries be added */ public static <V> int addDistinctList(List<V> sourceList, List<V> entryList) { if (sourceList == null || isEmpty(entryList)) { return 0; } int sourceCount = sourceList.size(); for (V entry : entryList) { if (!sourceList.contains(entry)) { sourceList.add(entry); } } return sourceList.size() - sourceCount; } /** * is null or its size is 0 * * <pre> * isEmpty(null) = true; * isEmpty({}) = true; * isEmpty({1}) = false; * </pre> * * @param <V> * @param sourceList * @return if list is null or its size is 0, return true, else return false. */ public static <V> boolean isEmpty(List<V> sourceList) { return (sourceList == null || sourceList.size() == 0); } }