Any null safe alternative to ArrayList.addAll?

后端 未结 4 1690
旧时难觅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 10:01

    Using Java 8:

    List fullImagePool = Stream.of(style.getTestMH(), /* etc */)
                                             .filter(Objects::nonNull)
                                             .flatMap(l -> l.stream())
                                             .collect(Collectors.toList());
    

提交回复
热议问题