Java List Create createIfNull(List list)

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

Description

It is common to want to make sure that a collection you receive is not null.

License

Apache License

Parameter

Parameter Description
list a parameter

Return

the passed in list if not null, otherwise a new ArrayList of the same type

Declaration

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

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**//  w  w  w . jav a  2s.  c  o m
     * It is common to want to make sure that a collection you receive is not null. Instead, we'd rather have
     * an empty list.
     * 
     * @param list
     * @return the passed in list if not null, otherwise a new ArrayList of the same type
     */
    public static <T> List<T> createIfNull(List<T> list) {
        return (list == null) ? new ArrayList<T>() : list;
    }
}

Related

  1. createEmptyListOfType(List original, boolean sameSize)
  2. createEntireInStatement(List values)
  3. createErrorStringFromList(List errorList)
  4. createGrantScript(List objectsToGrant, String grantee)
  5. createHTMLList(String list, String link, boolean APPEND, String title)
  6. createIndicesOrderedList(final Collection order, final Collection values)
  7. createInString(List keys)
  8. createIntArray(List coll)
  9. CreateIntArrayFromIntegerList(List solidsList)