Java Utililty Methods List Null Empty

List of utility methods to do List Null Empty

Description

The list of methods to do List Null Empty are organized into topic(s).

Method

ListnewListIfNull(List list)
new List If Null
if (list == null) {
    return new ArrayList<T>();
} else {
    return list;
ListnewListWhenNull(List list)
new List When Null
if (isEmpty(list)) {
    list = new ArrayList<T>();
return list;
ArrayListnewListWithOneNull()
new List With One Null
ArrayList<T> newList = new ArrayList<T>();
newList.add(null);
return newList;
booleannullOrEmpty(List s)
Check if List is null or empty
return s == null || s.isEmpty();
booleannullOrEmptyList(List list)
Determine if a List is null or empty.
return (list == null) || list.isEmpty();
voidnullSafeAdd(List list, T elem)
null Safe Add
if (list != null) {
    list.add(elem);
ListnullsafeAsList(T... elements)
nullsafe As List
return elements == null ? null : Arrays.asList(elements);
ListnullSafeList(List list)
Always returns a non-null list - either the argument list or a new empty list.
return list != null ? list : Collections.<O>emptyList();
ListnullToEmpty(List in)
null To Empty
return in == null ? Collections.<T>emptyList() : in;
ListnullToEmpty(List list)
null To Empty
return list == null ? Collections.emptyList() : list;