Search code examples
javajava-8bytejava-streamboxing

In Java 8, is there a ByteStream class?


Java 8 provides Stream<T> specializations for double, int and long: DoubleStream, IntStream and LongStream respectively. However, I could not find an equivalent for byte in the documentation.

Does Java 8 provide a ByteStream class?


Solution

  • No, it does not exist. Actually, it was explicitly not implemented so as not to clutter the Stream API with tons of classes for every primitive type.

    Quoting a mail from Brian Goetz in the OpenJDK mailing list:  

    Short answer: no.

    It is not worth another 100K+ of JDK footprint each for these forms which are used almost never. And if we added those, someone would demand short, float, or boolean.

    Put another way, if people insisted we had all the primitive specializations, we would have no primitive specializations. Which would be worse than the status quo.