Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of Collections.EMPTY_MAP, EMPTY_LIST, EMPTY_SET

Tags:

java

Since all of them are immutable, why would one want it?

like image 483
user855 Avatar asked May 30 '11 01:05

user855


1 Answers

Sometimes it's a better alternative to returning null.

public List<?> getList(){
    if(list == null){
        return Collections.emptyList();
    }

    return list;
}

Reference

like image 149
mre Avatar answered Oct 13 '22 11:10

mre