Collections.emptyList() instead of null check?

后端 未结 9 1116
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 02:59

If I have a rarely used collection in some class which may be instantiated many times, I may sometimes resort to the following \"idiom\" in order to save unnecessary object crea

9条回答
  •  猫巷女王i
    2021-02-04 03:29

    There is an emptyIfNull method in package org.apache.commons.collections4;. It returns an empty list if the one provided is null.

    List list = CollectionUtils.emptyIfNull(list);
    
        

    提交回复
    热议问题