DoubleStream boxed()返回由该流的元素组成的Stream,每个元素都装在Double中。
注意:DoubleStream boxed()是中间操作。这些操作总是很懒。在Stream实例上调用中间操作,并在完成处理后将中间实例作为输出提供。
用法:
Stream<Double> boxed()
参数:
- Stream : 支持顺序和并行聚合操作的一系列元素。
- Double : Double类将原始类型double的值包装在对象中。类型为Double的对象包含一个类型为double的单个字段。
返回值:该函数将装箱的流返回到Double。
示例1:
// Java code for DoubleStream boxed()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an DoubleStream
DoubleStream stream = DoubleStream.of(3.2, 8.4, 3.6, 4.7);
// Creating a Stream of Doubles
// Using DoubleStream boxed() to return
// a Stream consisting of the elements
// of this stream, each boxed to a Double.
Stream<Double> stream1 = stream.boxed();
// Displaying the elements
stream1.forEach(System.out::println);
}
}
输出:
3.2 8.4 3.6 4.7
示例2:
// Java code for DoubleStream boxed()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an DoubleStream
DoubleStream stream = DoubleStream.of(3.2, 8.4, 3.6, 4.7);
// Creating a Stream of Doubles
// Using DoubleStream boxed() to return
// a Stream consisting of the elements
// of this stream, each boxed to a Double.
Stream<Double> stream1 = stream.boxed();
Stream<Object> stream2 = Stream.concat(stream1,
Stream.of("Geeks", "for", "Geeks"));
// Displaying the elements
stream2.forEach(System.out::println);
}
}
输出:
3.2 8.4 3.6 4.7 Geeks for Geeks
相关用法
- Java DoubleStream min()用法及代码示例
- Java DoubleStream max()用法及代码示例
- Java DoubleStream anyMatch()用法及代码示例
- Java DoubleStream allMatch()用法及代码示例
- Java DoubleStream distinct()用法及代码示例
- Java DoubleStream peek()用法及代码示例
- Java DoubleStream filter()用法及代码示例
- Java DoubleStream average()用法及代码示例
- Java DoubleStream empty()用法及代码示例
- Java DoubleStream count()用法及代码示例
- Java DoubleStream limit()用法及代码示例
- Java DoubleStream noneMatch()用法及代码示例
- Java DoubleStream builder()用法及代码示例
- Java DoubleStream.Builder add(double t)用法及代码示例
- Java DoubleStream reduce(double identity, DoubleBinaryOperator op)用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 DoubleStream boxed() in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。