From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use the Streams API to process collections

Use the Streams API to process collections - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Use the Streams API to process collections

- [Narrator] When first learning how to code, you'll often iterate through an array or a list using a for-loop. While this is a perfectly acceptable way to go through elements in a collection, there are more concise ways to iterate through a list using newer Java features. The streams API was introduced in Java 8, and it helps you collapse your iteration into more concise readable code. Let's take a look. First, how do we create a stream? A stream is just a sequence of items. To create a stream outright you can use stream.of and then add the contents to your stream. For an array, you can use the array and then use a raised out stream to convert your array into a stream. For lists, you have access to adopt stream method on your list object. This method will return a stream. With our stream ready, we can begin to use streams functionality. Let's say we want to print out each item in the string. Instead of using a…

Contents