DoubleStream parallel() is a method in java.util.stream.DoubleStream. This method returns a parallel DoubleStream, i.e, it may return itself, either because the stream was already present, or because the underlying stream state was modified to be parallel.
DoubleStream parallel() is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
Syntax :
DoubleStream parallel()
Where, DoubleStream is a sequence of primitive
double-valued elements and the function
returns a parallel DoubleStream.
Example 1 :
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream =
DoubleStream.of( 5.2 , 12.6 , 4.5 , 7.8 );
System.out.println( "The corresponding "
+ "parallel DoubleStream is :" );
stream.parallel().forEach(System.out::println);
}
}
|
Output :
The corresponding parallel DoubleStream is :
4.5
7.8
12.6
5.2
Example 2 :
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream =
DoubleStream.of( 5.2 , 12.6 , 4.5 , 7.8 );
System.out.println( "The corresponding "
+ "sequential DoubleStream is :" );
stream.sequential().forEach(System.out::println);
}
}
|
Output :
The corresponding sequential DoubleStream is :
5.2
12.6
4.5
7.8
Example 3 :
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream =
DoubleStream.of( 2.3 , 3.0 , 4.5 , 6.6 );
System.out.println( "The sorted parallel"
+ " DoubleStream is :" );
stream.parallel().sorted().forEach(System.out::println);
}
}
|
Output :
The sorted parallel DoubleStream is :
4.5
6.6
2.3
3.0
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
06 Dec, 2018
Like Article
Save Article