Stream.of(T t) in Java with examples Last Updated : 06 Dec, 2018 Comments Improve Suggest changes 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 Create Quiz Comment S Sahil_Bansall Follow 0 Improve S Sahil_Bansall Follow 0 Improve Article Tags : Misc Java Java - util package Java-Functions java-stream Java-Stream interface +2 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like