Creating streams from different sources

In this recipe, you will learn how to create streams from different sources. You have different options, as the following:

  • The parallelStream() method of the Collection interface
  • The Supplier interface
  • A predefined set of elements
  • File and a directory
  • An array
  • A random number generator
  • The concatenation of two different streams

You can create a Stream object from other sources (that will be described in the There's more section), but we think that these are the more useful.

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.