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 rectanglegetArea: This returns its areatoString: 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 height, int width) {
this.x = x;
this.y = y;
this.height = height;
this.width = width;
}
public Rectangle scale(double percent) {
height = (int) (height * (1.0 + percent));...