Java List Null Empty nullSafeList(List list)

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

Description

Always returns a non-null list - either the argument list or a new empty list.

License

Apache License

Parameter

Parameter Description
list for which we want safe access

Return

a non-null list

Declaration

public static <O extends Object> List<O> nullSafeList(List<O> list) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collections;

import java.util.List;

public class Main {
    /**/*w w  w . j a  va 2s .co  m*/
     * Always returns a non-null list - either the argument list or
     * a new empty list.
     * 
     * @param list for which we want safe access
     * @return a non-null list
     */
    public static <O extends Object> List<O> nullSafeList(List<O> list) {
        return list != null ? list : Collections.<O>emptyList();
    }
}

Related

  1. newListWithOneNull()
  2. nullOrEmpty(List s)
  3. nullOrEmptyList(List list)
  4. nullSafeAdd(List list, T elem)
  5. nullsafeAsList(T... elements)
  6. nullToEmpty(List in)
  7. nullToEmpty(List list)
  8. nullToEmpty(List nullable)