IntStream asLongStream() in Java
Last Updated :
06 Dec, 2018
IntStream asLongStream() returns a LongStream consisting of the elements of this stream, converted to long. This 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 asLongStream()
Where, LongStream is a sequence of
primitive long-valued element.
Return Value : IntStream asLongStream() returns a LongStream consisting of the elements of this stream, converted to long.
Example 1 :
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
class GFG {
public static void main(String[] args)
{
IntStream stream = IntStream.of( 3 , 5 , 9 , 12 , 14 );
LongStream stream1 = stream.asLongStream();
stream1.forEach(System.out::println);
}
}
|
Output :
3
5
9
12
14
Example 2 :
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
class GFG {
public static void main(String[] args)
{
LongStream stream = IntStream.range( 3 , 8 ).asLongStream();
stream.forEach(System.out::println);
}
}
|
Output :
3
4
5
6
7
Share your thoughts in the comments
Please Login to comment...