LongStream sequential() in Java
LongStream sequential() returns a sequential LongStream. It may return itself, either because the stream was already sequential, or because the underlying stream state was modified to be sequential. LongStream 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 :
LongStream sequential()
Where, LongStream is a sequence of primitive
long-valued element.
Example 1 :
import java.util.*;
import java.util.stream.LongStream;
class GFG {
public static void main(String[] args)
{
LongStream stream = LongStream.of(3L, 5L, 9L, 12L, 14L);
LongStream streamNew = stream.sequential();
streamNew.forEach(System.out::println);
}
}
|
Example 2 :
import java.util.*;
import java.util.stream.LongStream;
class GFG {
public static void main(String[] args)
{
LongStream stream = LongStream.range(-2L, 4L);
LongStream streamNew = stream.sequential();
streamNew.forEach(System.out::println);
}
}
|
Last Updated :
06 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...