Any null safe alternative to ArrayList.addAll?

后端 未结 4 1801
旧时难觅i
旧时难觅i 2021-02-02 09:35

I was refactoring some old code of mine that I\'ve written and I stumbeled on this code:

    List fullImagePool = new ArrayList<>();
           


        
4条回答
  •  忘了有多久
    2021-02-02 09:42

    In Java 8 Use below code:-

    Optional.ofNullable(listToBeAdded).ifPresent(listToBeAddedTo::addAll)
    

    listToBeAdded - The list whose elements are to be added. listToBeAddedTo - The list to which you are adding elements using addAll.

提交回复
热议问题