Here you can find the source of getSize(List
null
or empty, else the count getSize(null) = 0; getSize({}) = 0; getSize({1}) = 1;
Parameter | Description |
---|---|
V | < > |
list | - of List type. |
public static <V> int getSize(List<V> list)
//package com.java2s; import java.util.List; public class Main { /**/* ww w. j ava 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(); } }