The toArray()
method of the LongStream
interface is used to create a long
type array that consists of the elements in the stream. This method is a terminal/last operation in the stream pipeline.
long[] toArray();
This method has no parameters.
This method returns a long
type array.
import java.util.Arrays;import java.util.stream.LongStream;class Main {public static void main(String[] args) {LongStream longStream = LongStream.range(5, 10);long[] longArray = longStream.toArray();System.out.println("Converting the longStream to an array - " + Arrays.toString(longArray));}}
Arrays
class and the LongStream
interface.long
values, using the range()
method of the LongStream
interface.long
array, using the toArray()
method.