如何从 float[] 中获取 Stream [英] How to get a Stream from a float[]
问题描述
当我发现一些奇怪的东西时,我正在学习如何使用 java 8 流.
I was learning how to use java 8 streams when I noticed something weird.
Arrays.stream()
有除浮点数组以外的所有方法:
Arrays.stream()
has methods for everything but float arrays :
Arrays.stream(int[]) : IntStream
Arrays.stream(long[]) : LongStream
Arrays.stream(double[]) : DoubleStream
同样,有 int、double 等的 Stream 实现,但没有浮点数:
Similarly, there are Stream implementations for int, double etc but not floats :
IntStream
LongStream
双流
有什么原因吗?
使用浮动流的推荐方法是什么?
what is the recommended way to work with float streams?
推荐答案
来自 Java SE 8 for the Real Impatient
by Cay S. Horstmann :
from Java SE 8 for the Really Impatient
by Cay S. Horstmann :
2.12.原始类型流
... 如果要存储 short、char、byte 和 boolean,请使用IntStream,对于浮点数,使用 DoubleStream.图书馆设计师认为不值得再添加五种流类型.
... 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.
这篇关于如何从 float[] 中获取 Stream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!