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

booleanisNullOrEmpty(List l)
is Null Or Empty
if (l == null) {
    return true;
if (l.isEmpty()) {
    return true;
return false;
booleanisNullOrEmptyAwareEqual(final List targetOne, final List targetTwo)
Check if either both objects are null or List#isEmpty() empty .
final boolean checkResult;
if (targetOne == null || targetOne.isEmpty()) {
    checkResult = targetTwo == null || targetTwo.isEmpty();
} else {
    checkResult = targetOne.equals(targetTwo);
return checkResult;
booleanisNullOrEmptyList(final List list)
is Null Or Empty List
return list == null || list.size() == 0;
voidisNullOrEmptyList(List list)
is Null Or Empty List
isNullOrEmptyList(list, "[Assertion failed] - this list is empty or null");
voidisNullOrEmptyList(String message, List list)
is Null Or Empty List
if ((null == list) || (list.isEmpty())) {
    throw new IllegalArgumentException(message);
booleanisObjectListEmpty(List list)
This method returns true if the input list is null or list is empty.
return (list == null || list.isEmpty());
TlistToItemOrNull(List list)
Transforms a list to a single item or to a null if the list has no item.
if (list == null) {
    return null;
} else {
    switch (list.size()) {
    case 0:
        return null;
    case 1:
        return list.get(0);
...
ListlistWithoutNull(A... elements)
list Without Null
List<A> list = new ArrayList<A>();
for (A a : elements) {
    if (a != null)
        list.add(a);
return list;
ListlistWithoutNull(final List list)
Return a list without null elements.
if (list == null) {
    return null;
final List<E> result = new ArrayList<>();
for (E e : list) {
    if (e != null) {
        result.add(e);
return result;
ListmaskNull(List pTypes)
mask Null
return (pTypes == null) ? Collections.<String>emptyList() : pTypes;