问题描述
当我注意到一些奇怪的东西时,我正在学习如何使用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
Arrays.stream(int[]) : IntStream
Arrays.stream(long[]) : LongStream
Arrays.stream(double[]) : DoubleStream
同样,有流int,double等实现但不是浮点数:
Similarly, there are Stream implementations for int, double etc but not floats :
-
IntStream
-
LongStream
-
DoubleStream
IntStream
LongStream
DoubleStream
这有什么理由吗?
使用浮动流的推荐方法是什么?
what is the recommended way to work with float streams?
推荐答案
来自 Java SE 8 for the Really Impatient
by Cay S. Horstmann:
from Java SE 8 for the Really Impatient
by Cay S. Horstmann :
...如果要存储short,char,byte和boolean,请使用
IntStream,对于float,使用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 []获取流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!