See how to rewrite the Map function from scratch, first using a "for" loop, then using the Collect function.
(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. …
Skill Level Advanced
Java Design Patterns: Structuralwith Bethan Palmer1h 38m Intermediate
1. Introduction to Functional Programming
2. First-Class Functions
3. Working with Streams in Java
4. Advanced Concepts
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.