Scala StreamStream 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 ExampleIn the following program, we have created a stream. Output: Stream(100, ?) 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 MethodsIn the following example, we have used some predefined methods like toStream, which is used to iterate stream elements. Output: Stream(100, ?) Stream(1, ?) 1 Stream(1, ?) Stream(200, ?)
Next TopicScala Maps
|