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 an empty sequential stream.
Note : An empty stream might be useful to avoid null pointer exceptions while callings methods with stream parameters.
Example :
// Java code for Stream empty() import java.util.*; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Creating an empty Stream Stream<String> stream = Stream.empty(); // Displaying elements in Stream stream.forEach(System.out::println); } } |
Output :
No Output
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- LongStream empty() in Java with examples
- IntStream empty() in Java with examples
- DoubleStream empty() in Java with examples
- OptionalInt empty() method in Java with examples
- OptionalLong empty() method in Java with examples
- Optional empty() method in Java with examples
- OptionalDouble empty() method in Java with examples
- Stream.of(T t) in Java with examples
- Stream map() in Java with examples
- Stream builder() in Java with Examples
- Stream flatMapToInt() in Java with examples
- Stream flatMapToLong() in Java with examples
- Stream.reduce() in Java with examples
- Stream toArray() in Java with Examples
- Stream flatMapToDouble() in Java with examples
- Stream.of(T... values) in Java with examples
- Stream peek() in Java with examples
- Stream mapToDouble() in Java with examples
- Stream mapToLong() in Java with examples
- Stream mapToInt() in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

