DoubleStream sequential() in Java
DoubleStream sequential() returns a sequential DoubleStream. It may return itself, either because the stream was already sequential, or because the underlying stream state was modified to be sequential.
DoubleStream sequential() is an intermediate operation. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
Syntax :
DoubleStream sequential()
Where, DoubleStream is a sequence of primitive
double-valued element.
Return Value : A sequential DoubleStream.
Example 1 : DoubleStream sequential() to return a sequential DoubleStream.
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream = DoubleStream.of( 3.3 , 5.4 , 9.2 ,
12.1 , 14.4 );
DoubleStream streamNew = stream.sequential();
streamNew.forEach(System.out::println);
}
}
|
Output:
3.3
5.4
9.2
12.1
14.4
Example 2 : DoubleStream sequential() on empty DoubleStream.
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream = DoubleStream.empty();
System.out.println( "parallel : " + stream.isParallel());
stream = stream.parallel();
System.out.println( "parallel : " + stream.isParallel());
stream = stream.sequential();
System.out.println( "parallel : " + stream.isParallel());
}
}
|
Output:
parallel : false
parallel : true
parallel : false
Last Updated :
06 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...