Open In App

DoubleStream of() in Java

Improve
Improve
Like Article
Like
Save
Share
Report

DoubleStream of(double t)

DoubleStream of(double t) returns a sequential DoubleStream containing a single element.
Syntax :

static DoubleStream of(double t)

Parameters :

  1. DoubleStream : A sequence of primitive double-valued elements.
  2. t : Represents the single element in the DoubleStream.

Return Value : DoubleStream of(double t) returns a sequential DoubleStream containing the single specified element.

Example :




// 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);
    }
}


Output :

8.2

DoubleStream of(double… values)

DoubleStream of(double… values) returns a sequential ordered stream whose elements are the specified values.
Syntax :

static DoubleStream of(double... values)

Parameters :

  1. DoubleStream : A sequence of primitive double-valued elements.
  2. values : Represents the elements of the new stream.

Return Value : DoubleStream of(double… values) returns a sequential ordered stream whose elements are the specified values.

Example 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);
    }
}


Output :

8.2
5.6
4.1

Example 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);
    }
}


Output :

3


Last Updated : 06 Dec, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads