From the course: Java: Lambdas and Streams
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Using streams - Java Tutorial
From the course: Java: Lambdas and Streams
Using streams
- [Instructor] So now let's start writing some streams. There are two ways to create a stream, and luckily they're both quite simple. The most common use of a stream is to create a stream from an existing array or collection. So, I have a class already set up here called Main which has a main method in it, and in my method, I've got an array called scores with some numbers in. So it's got 80, 66, 73, 92, and 43. So, to create a stream from this array, I first need to create a stream variable. So I'm going to type stream, and then in angle brackets, I put the type of the stream. So this one is going to be integer, and I also need to make sure that I'm importing the right class. So IntelliJ will do this for me if I click Alt + Enter, and it will import java.util.stream.Stream. So, I need to give this variable a name. So I'm going to call it scoresStream, and then after the equals I'm going to do Arrays.stream, and then pass…