Stream of(T t)
Stream of(T t) returns a sequential Stream containing a single element.
Syntax :
static Stream of(T t)
Parameters: This method accepts a mandatory parameter t which is the single element in the Stream.
Return Value: Stream of(T t) returns a sequential Stream containing the single specified element.
Example :
import java.util.*;
import java.util.stream.Stream;
class GFG {
public static void main(String[] args)
{
Stream stream = Stream.of( "Geeks" );
stream.forEach(System.out::println);
}
}
|
Stream of(T… values)
Stream of(T… values) returns a sequential ordered stream whose elements are the specified values.
Syntax :
static Stream of(T... values)
Parameters: This method accepts a mandatory parameter values which are the elements of the new stream.
Return Value : Stream of(T… values) returns a sequential ordered stream whose elements are the specified values.
Example:
import java.util.*;
import java.util.stream.Stream;
class GFG {
public static void main(String[] args)
{
Stream stream = Stream.of( "Geeks" , "for" , "Geeks" );
stream.forEach(System.out::println);
}
}
|