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.

Create Lambdas to pass functionality as data

Create Lambdas to pass functionality as data - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Create Lambdas to pass functionality as data

- [Instructor] Lambdas introduce some functional programming support in Java 8, that allows you to pass functions as data. In the past, whenever we've created a function, we have always had to put it inside of a class. Sometimes, we want to create functions on the fly and not assign them to a class. We want to use them for a single purpose in the moment to calculate something. Lambdas give us a way to do just this. Let's take a look. In this code, we create a student's array list and add a few students. Instead of using a for loop to iterate through each student, we write simpler code that uses a Lambda expression. Let's run it. And here are the students. In this code, we use the forEach method to iterate through all of the students and print each one. In the Lambda function, the value of S becomes a given student name, as the iteration takes place. This is a very common imperative pattern in enterprise code, that…

Contents