Java IntStream asDoubleStream()

Java IntStream asDoubleStream()

IntStream asDoubleStream() 返回一个由这个流的元素组成的 DoubleStream ,并转换为双数。这是一个 中间操作, 中间操作是在一个Stream实例上调用的,在它们完成处理后,会给出一个Stream实例作为输出。

语法:

DoubleStream asDoubleStream()

其中,DoubleStream是一连串的
原始的双值元素。
返回值 : IntStream asDoubleStream() 返回一个由该流元素组成的
由这个流的元素组成的DoubleStream。
转换为双数。

例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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程