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

ListemptyStringList()
empty String List
return new ArrayList<String>();
ListemptyToNull(List list)
empty To Null
if (isEmpty(list)) {
    return null;
return list;
ListemptyToNull(List list)
empty To Null
return list == null ? null : (list.isEmpty() ? null : list);
booleanequalsEmptyEqNull(List list1, List list2)
equals Empty Eq Null
if ((list1 == null || list1.isEmpty()) && (list2 == null || list2.isEmpty())) {
    return true;
if (list1 == null || list2 == null) {
    return false;
for (int i = 0; i < list1.size(); i++) {
    if (!list1.get(i).equals(list2.get(i))) {
...
booleanequalsNullSafe(List list1, List list2)
equals Null Safe
if (list1 == list2) {
    return true;
if (list1 == null) {
    return list2 == null;
if (list2 == null) {
    return list1 == null;
...
voidfillEmptyEntries(Iterable keys, Map> map)
Adds a references to the empty list for keys to the map that are currently not yet contained in this map.
for (Long processId : keys) {
    if (!map.containsKey(processId)) {
        List<T> empty = Collections.emptyList();
        map.put(processId, empty);
voidfillNull(final List list, final int numElements)
fill Null
if (numElements < list.size())
    return;
final int iterations = numElements - list.size();
for (int i = 0; i < iterations; i++) {
    list.add(null);
voidfillNull(List lst, int size)
fill Null
for (int i = lst.size(); i < size; i++) {
    lst.add(null);
ListfillUpWithNulls(List list)
Expands an integer list to a size equal to its value range and adds null-value entries for every missing intermediate integer value.
return fillUpWithNulls(list, null);
ListgetEmptyList(Class cls)
get Empty List
return (List<T>) emptyList;