Stream API has many useful methods. If we want to transform a
Stream to a Java array we can use the
toArray method. Without an argument the result is an object array (
Object), but we can also use an argument to return an array of another type. The easiest way is to use the contructor of the array type we want as method reference. Then the result is an array of the given type with the elements of the stream.