Get size of list, Returns 0 if the provided List is null or empty, else the count getSize(null) = 0; getSize({}) = 0; getSize({1}) = 1; - Android java.util

Android examples for java.util:List

Description

Get size of list, Returns 0 if the provided List is null or empty, else the count getSize(null) = 0; getSize({}) = 0; getSize({1}) = 1;

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    /**/*ww w . ja  v  a 2 s . c  o m*/
     * Get size of list, Returns 0 if the provided {@link List} is <code>null</code> or empty, else the count
     * 
     * <pre>
     * getSize(null)   =   0;
     * getSize({})     =   0;
     * getSize({1})    =   1;
     * </pre>
     * 
     * @param <V> 
     * @param list - of {@link List} type.
     * @return int -if list is null or empty, return 0, else return {@link List#size()}.
     */
    public static <V> int getSize(List<V> list) {
        return list == null ? 0 : list.size();
    }
}

Related Tutorials