Creating streams

Streams can be of fixed or infinite length. In the previous example, we used an array of integers to create a fixed length stream. However, if we want to process data arriving through a network connection, this stream of data may appear to be infinite. We can create both types of streams in Java 8.

We will use a Rectangle class to demonstrate the use of streams in several sections of this chapter. The class possesses position and dimension variables and three methods:

  • scale: This changes the size of a rectangle
  • getArea: This returns its area
  • toString: This displays its values

The class declaration follows:

public class Rectangle { private int x; private int y; private int height; private int width; public Rectangle(int x, int y, int ...

Get Learning Java Functional Programming 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.