Arnaud Denoyelle Arnaud Denoyelle - 6 months ago 46
Java Question

How to get a Stream from a float[]

I was learning how to use java 8 streams when I noticed something weird.

Arrays.stream()
has methods for everything but float arrays :


  • Arrays.stream(int[]) : IntStream

  • Arrays.stream(long[]) : LongStream

  • Arrays.stream(double[]) : DoubleStream



Similarly, there are Stream implementations for int, double etc but not floats :


  • IntStream

  • LongStream

  • DoubleStream



Is there a reason for that?

what is the recommended way to work with float streams?

Answer

from Java SE 8 for the Really Impatient by Cay S. Horstmann :

2.12. Primitive Type Streams

... If you want to store short, char, byte, and boolean, use an IntStream, and for float, use a DoubleStream. The library designers didn’t think it was worth adding another five stream types.