Utility to check null and return size as 0 if empty for a collection/list in java
java
Solution
What about
int size = (list == null) ? 0 : list.size();
I'm not sure why you would want a utility for this, since the above seems simple enough.
Problem
I have list which can be null sometimes, the return type should be int ex: ``` int size = 0; if(list != null) { size = list.size; } ``` Could you please let me know whether any utility is available? Thanks.