Java Streams - Stream empty() example








Stream empty() creates an empty sequential Stream.

Syntax

empty has the following syntax.

static <T> Stream<T> empty()

Example

The following example shows how to use empty.

import java.util.stream.Stream;
/*  ww w.  j  ava 2 s . c  o m*/
public class Main {
  public static void main(String[] args) {
    Stream<String> s = Stream.empty();
    s.limit(10)
     .forEach(System.out::println); 

  }
}