📜  Java中的 DoubleStream of()

📅  最后修改于: 2022-05-13 01:55:11.076000             🧑  作者: Mango

Java中的 DoubleStream of()

DoubleStream of(double t)

DoubleStream of(double t)返回包含单个元素的顺序 DoubleStream。
句法 :

static DoubleStream of(double t)

参数 :

  1. DoubleStream :原始双值元素的序列。
  2. t :表示 DoubleStream 中的单个元素。

返回值: DoubleStream of(double t) 返回包含单个指定元素的顺序 DoubleStream。

例子 :

// Java code for DoubleStream of(double t)
// to get a sequential DoubleStream
// containing a single element.
import java.util.*;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating a DoubleStream having single
        // element only
        DoubleStream stream = DoubleStream.of(8.2);
  
        // Displaying the DoubleStream having 
        // single element
        stream.forEach(System.out::println);
    }
}

输出 :

8.2

DoubleStream of(double… values)

DoubleStream of(double… values)返回一个顺序有序的流,其元素是指定的值。
句法 :

static DoubleStream of(double... values)

参数 :

  1. DoubleStream :原始双值元素的序列。
  2. values :表示新流的元素。

返回值: DoubleStream of(double… values) 返回一个顺序有序的流,其元素是指定的值。

示例 1:

// Java code for DoubleStream of(double... values)
// to get a sequential ordered stream whose
// elements are the specified values.
import java.util.*;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an DoubleStream
        DoubleStream stream = DoubleStream.of(8.2, 5.6, 4.1);
  
        // Displaying the sequential ordered stream
        stream.forEach(System.out::println);
    }
}

输出 :

8.2
5.6
4.1

示例 2:

// Java code for DoubleStream of(double... values)
// to get a sequential ordered stream whose
// elements are the specified values.
import java.util.*;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an DoubleStream
        DoubleStream stream = DoubleStream.of(5.2, 4.2, 6.3);
  
        // Storing the count of elements in DoubleStream
        long total = stream.count();
  
        // Displaying the count of elements
        System.out.println(total);
    }
}

输出 :

3