Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't I use Arrays.stream(boolean[])?

I am unable to understand why the following does not work ?

boolean[] a = new boolean[5];
Arrays.stream(a);

I keep getting the error :

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried using the generic parameter:

Arrays.<Boolean>stream(a);

I can’t seem to figure it out.

What am I completely missing ?

I am using OpenJDK 11.

>Solution :

There is support for primitives int, long and double. The idea is that char, byte and short can be handled by int, float by double, and boolean by Boolean. The only main issue there is the conversion of array to stream.

This can be solved using a simple workaround:

Stream<Boolean> boolStream = IntStream.range(0, array.length)
        .mapToObj(i -> array[i]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading