How do you create a stream Boolean.FALSE, say, a length of 100?
What I struggled with:
- I originally intended to create an array
Boolean.FALSE. But it new Boolean[100]returns an array NULL. Therefore, I reasonably considered using the stream API as a convenient tool Iterableand almost ( 1 ) Iterable; - There is no no
Booleanno-params constructor ( 2 ), so I can’t use Stream.generate(), since it accepts Supplier<T>( 3 ).
What I found Stream.iterate(Boolean.FALSE, bool -> Boolean.FALSE).limit(100);gives what I want, but it does not seem like a pretty elegant solution, IMHO.
Another option I found ( 4 ) IntStream.range(0, 100).mapToObj(idx -> Boolean.FALSE);, which seems even weirder to me.
Despite the fact that these parameters do not violate the concept of the stream API pipeline, are there more concise ways to create a stream Boolean.FALSE?
source
share