VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. The power of Stream.of() in Java
Programming Blog

Atom/RSS Feed

java

The power of Stream.of() in Java

java

Stream.of() can be used instead of creating an array then iterating over it.

Java stream example

Stream.of(1,2,3).forEach(System.out::println);

Results in:

1

2

3

Even Better yet

If the order of execution does not matter you can execute Stream in .parallel()

Stream.of(1,2,3).parallel().forEach(System.out::println);

Results in an unpredictable output order such as:

3

1

2

Join my mailing list