Stream.of(T t) in Java with examples Last Updated : 06 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report Stream of(T t) returns a sequential Stream containing a single element i.e, a singleton sequential stream. A sequential stream work just like for-loop using a single core. On the other hand, a Parallel stream divide the provided task into many and run them in different threads, utilizing multiple cores of the computer. Syntax : static <T> Stream<T> of(T t) Where, Stream is an interface and T is the type of stream elements. t is the single element and the function returns a singleton sequential stream. Example 1 : Singleton string stream. Java // Java code for Stream.of() // to get sequential Stream // containing a single element. import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // creating a stream of Strings // and printing sequential Stream // containing a single element Stream<String> stream = Stream.of("Geeks"); stream.forEach(System.out::println); } } Output : Geeks Example 2 : Singleton Integer Stream. Java // Java code for Stream.of() // to get sequential Stream // containing a single element. import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // creating a stream of Integer // and printing sequential Stream // containing a single element Stream<Integer> stream = Stream.of(5); stream.forEach(System.out::println); } } Output : 5 Example 3 : Singleton Long stream. Java // Java code for Stream.of() // to get sequential Stream // containing a single element. import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // creating a stream of Long // and printing sequential Stream // containing a single element Stream<Long> stream = Stream.of(4L); stream.forEach(System.out::println); } } Output : 4 Comment More infoAdvertise with us Next Article Stream mapToLong() in Java with examples S Sahil_Bansall Follow Improve Article Tags : Misc Java Java - util package Java-Functions java-stream Java-Stream interface +2 More Practice Tags : JavaMisc Similar Reads Stream.of(T... values) in Java with examples Stream of(T... values) returns a sequential ordered stream whose elements are the specified values. A sequential stream works like a for-loop using a single core. On the other hand, a Parallel stream divides the provided task into many tasks and runs them in different threads, utilizing multiple cor 3 min read Stream toArray() in Java with Examples Stream toArray() returns an array containing the elements of this stream. It is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. After the terminal operation is performed, the stream pipeline is considered consumed, and can no longer be used. Syntax : Object 2 min read Stream mapToInt() in Java with examples Stream mapToInt(ToIntFunction mapper) returns an IntStream consisting of the results of applying the given function to the elements of this stream. Stream mapToInt(ToIntFunction mapper) is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream in 2 min read Stream mapToLong() in Java with examples Stream mapToLong(ToLongFunction mapper) returns a LongStream consisting of the results of applying the given function to the elements of this stream. Stream mapToLong(ToLongFunction mapper) is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Strea 2 min read Stream empty() in Java with Examples Stream empty() creates an empty sequential Stream. Syntax : static <T> Stream<T> empty() Parameters : T : The type of stream elements. Stream : A sequence of objects that supports various methods which can be pipelined to produce the desired result. Return Value : Stream empty() returns 1 min read Stream filter() in Java with examples Stream filter(Predicate predicate) returns a stream consisting of the elements of this stream that match the given predicate. This is an intermediate operation. These operations are always lazy i.e, executing an intermediate operation such as filter() does not actually perform any filtering, but ins 3 min read Like