Java List Null Empty emptyToNull(List list)

Here you can find the source of emptyToNull(List list)

Description

empty To Null

License

Open Source License

Declaration

public static <T> List<T> emptyToNull(List<T> list) 

Method Source Code


//package com.java2s;

import java.util.Collection;

import java.util.List;
import java.util.Map;

public class Main {
    public static <T> List<T> emptyToNull(List<T> list) {
        if (isEmpty(list)) {
            return null;
        }//from w  w w  .  j  ava 2  s  .c  om
        return list;
    }

    public static <T> boolean isEmpty(T[] vals) {
        return vals == null || vals.length == 0;
    }

    public static <T> boolean isEmpty(T[] vals, boolean checkNullVal) {
        boolean isEmpty = vals == null || vals.length == 0;
        if (isEmpty) {
            return true;
        }
        if (checkNullVal) {
            for (T val : vals) {
                if (val != null) {
                    return false;
                }
            }
            isEmpty = true;
        }
        return isEmpty;
    }

    public static boolean isEmpty(Collection<?> col) {
        return col == null || col.isEmpty();
    }

    public static <T, V> boolean isEmpty(Map<T, V> map) {
        return map == null || map.isEmpty();
    }
}

Related

  1. addListNotNullValue(List sourceList, V value)
  2. addNonEmpty(List list, String value)
  3. addNotNull(List list, T t)
  4. countIgnoreNull(List list)
  5. emptyStringList()
  6. emptyToNull(List list)
  7. equalsEmptyEqNull(List list1, List list2)
  8. equalsNullSafe(List list1, List list2)
  9. fillEmptyEntries(Iterable keys, Map> map)