Skip to content
Related Articles

Related Articles

Stream empty() in Java with Examples

Improve Article
Save Article
  • Last Updated : 06 Dec, 2018
Improve Article
Save Article

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.*;
class GFG {
    // Driver code
    public static void main(String[] args)
        // Creating an empty Stream
        Stream<String> stream = Stream.empty();
        // Displaying elements in Stream

Output :

No Output
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!