From the course: Functional Programming with Java

Unlock the full course today

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

Solution: Stream exercises

Solution: Stream exercises - Java Tutorial

From the course: Functional Programming with Java

Start my 1-month free trial

Solution: Stream exercises

(upbeat music) - [Instructor] Okay, so let's take a look at the solutions for the three challenges that I gave you. For this first one where we're supposed to take a list of people objects and return a list that contains only their names, here's what I did. I started off by saying ListStrings, since we know that we want our answer here to be a list of strings, and we're going to say peopleNames equals, and then we're going to say people and convert it to a stream by using dot stream. And then we're going to use the map function for this one. And for this map function what we're going to do, is we're going to take each person and we're going to return person.name. And finally, we're going to use collect with collectors.toList, to take this stream and turn it back into a list. So let's log out that answer to make sure I got that right there. So let's run this code here just to make sure I got the right answer. So I want to log out people names instead of people. So let's try that again.…

Contents