O'Reilly logo

Learning Java Functional Programming by Richard M Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required