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 theCollection
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.
Getting ready
The example of this recipe has been implemented using the Eclipse IDE. If you use Eclipse or other IDE such as NetBeans, open it and create a new Java project.
How to do it...
In this recipe we'll implement an example where you will learn how to create streams from the sources described earlier. Follow these steps to implement the example:
- First, we'll implement some auxiliary classes that we will use in the example. Create a class named
Person
with six attributes of different...