Java-8: boolean primitive array to stream?

前端 未结 4 1825
梦毁少年i
梦毁少年i 2020-12-17 08:51

There is no nice way to convert given boolean[] foo array into stream in Java-8 in one statement, or I am missing something?

(I

4条回答
  •  春和景丽
    2020-12-17 09:27

    You can use Guava's Booleans class:

    Stream stream = Booleans.asList(foo).stream();
    

    This is a pretty efficient way because Booleans.asList returns a wrapper for the array and does not make any copies.

提交回复
热议问题