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 - Java Tutorial
From the course: Nail Your Java Interview
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understand the impact of Jigsaw2m 40s
-
(Locked)
Use optionals to avoid NullPointerExceptions3m 26s
-
(Locked)
Create Lambdas to pass functionality as data5m 14s
-
(Locked)
Use the Streams API to process collections3m 57s
-
(Locked)
Discuss the pros and cons of local variable type inference2m 42s
-
(Locked)
Leverage new switch expressions3m 36s
-
-
-
-
-
-