checks for a null list and returns Collections.emptyList in that case. - Java java.util

Java examples for java.util:Collection Search

Description

checks for a null list and returns Collections.emptyList in that case.

Demo Code


//package com.java2s;

import java.util.Collections;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(getListValue(list));
    }//from w ww.  ja va  2s  .c o  m

    public static <T> List<T> getListValue(List<T> list) {
        if (list == null) {
            return Collections.emptyList();
        }

        return list;
    }
}

Related Tutorials