IntStream asDoubleStream()返回包含此流元素的DoubleStream,并将其转换为double。这是一个中间操作。在Stream实例上调用中间操作,并在完成处理后将中间实例作为输出提供。
用法:
DoubleStream asDoubleStream() Where, DoubleStream is a sequence of primitive double-valued element. 返回值:IntStream asDoubleStream() returns a DoubleStream consisting of the elements of this stream, converted to double.
范例1:
// Java code for DoubleStream asDoubleStream()
// to return a DoubleStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream
IntStream stream = IntStream.of(3, 5, 9, 12, 14);
// Using DoubleStream asDoubleStream()
DoubleStream stream1 = stream.asDoubleStream();
// Displaying DoubleStream consisting of
// the elements of this stream
stream1.forEach(System.out::println);
}
}
输出:
3.0 5.0 9.0 12.0 14.0
范例2:
// Java code for DoubleStream asDoubleStream()
// to return a DoubleStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream and using asDoubleStream()
DoubleStream stream = IntStream.range(3, 8).asDoubleStream();
// Displaying DoubleStream consisting of
// the elements of this stream
stream.forEach(System.out::println);
}
}
输出:
3.0 4.0 5.0 6.0 7.0
范例3:
// Java code for DoubleStream asDoubleStream()
// to return a DoubleStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream and using asDoubleStream()
// to display the elements of IntStream and
// DoubleStream together
DoubleStream stream = IntStream.range(3, 8)
.peek(System.out::println)
.asDoubleStream();
// Displaying DoubleStream consisting of
// the elements of this stream
stream.forEach(System.out::println);
}
}
输出:
3 3.0 4 4.0 5 5.0 6 6.0 7 7.0
相关用法
- Java LongStream asDoubleStream()用法及代码示例
- Java IntStream of()用法及代码示例
- Java IntStream sum()用法及代码示例
- Java IntStream mapToObj()用法及代码示例
- Java IntStream boxed()用法及代码示例
- Java IntStream builder()用法及代码示例
- Java IntStream iterator()用法及代码示例
- Java IntStream rangeClosed()用法及代码示例
- Java IntStream mapToLong()用法及代码示例
- Java IntStream sequential()用法及代码示例
- Java IntStream sorted()用法及代码示例
- Java IntStream range()用法及代码示例
- Java IntStream summaryStatistics()用法及代码示例
- Java IntStream asLongStream()用法及代码示例
- Java IntStream limit()用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 IntStream asDoubleStream() in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。