LongStream of(long t)
LongStream of(long t) returns a sequential LongStream containing a single element.
Syntax :
static LongStream of(long t)
Parameters :
- LongStream : A sequence of primitive long-valued elements.
- t : Represents the single element in the LongStream.
Return Value : LongStream of(long t) returns a sequential LongStream containing the single specified element.
Example :
import java.util.*;
import java.util.stream.LongStream;
class GFG {
public static void main(String[] args)
{
LongStream stream = LongStream.of(-7L);
stream.forEach(System.out::println);
}
}
|
LongStream of(long… values)
LongStream of(long… values) returns a sequential ordered stream whose elements are the specified values.
Syntax :
static LongStream of(long... values)
Parameters :
- LongStream : A sequence of primitive long-valued elements.
- values : Represents the elements of the new stream.
Return Value : LongStream of(long… values) returns a sequential ordered stream whose elements are the specified values.
Example 1 :
import java.util.*;
import java.util.stream.LongStream;
class GFG {
public static void main(String[] args)
{
LongStream stream = LongStream.of(-7L, -9L, -11L);
stream.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.of(-7L, -9L, -11L);
long total = stream.count();
System.out.println(total);
}
}
|