Stream is a lazy list. It evaluates elements only when they are required. This is a feature of scala. Scala supports lazy computation. It increases performance of your program.
Scala Stream Example
In the following program, we have created a stream.
In the output, you can see that second element is not evaluated. Here, a question mark is displayed in place of element. Scala does not evaluate list until it is required.
Scala Stream Example: Applying Predefined Methods
In the following example, we have used some predefined methods like toStream, which is used to iterate stream elements.
Stream(100, ?) Stream(1, ?) 1 Stream(1, ?) Stream(200, ?)