Java8: Lambdas & Streams

Photo by Mitchell Kmetz on Unsplash

When streams combined with lambdas we can do a lot with very few lines of codes. Let’s try to print below class using streams.

public class Person{
String name;
int age;
Person(String name, int age){
this.age=age;
this.name=name;
}
}

First we will convert the list to a stream and do a filter to find the names start with s. Then filtered results to be printed.

List<Person> list= Arrays.asList(
new Person("nuwan",20),
new Person("sen",30)
);

list.stream()
.filter(person -> person.name.startsWith("s"))
.forEach(person -> System.out.println(person.name));

Read my other blogs:

--

--

--

Sometimes A software Engineer, sometimes a support engineer, sometimes a devops engineer, sometimes a cloud engineer :D That’s how the this life goes!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Perl 6 small stuff #9: Vantage points and the perception of speed

Logitech G G733 on MacBook M1 — Apple Silicon

True Story of Ever Surf for Desktop

How to Create a Group of Custom Fields with Meta Box Group

Scrum Master domain competence model — a proposition

How to deploy app on Heroku?

Top 5 trending technologies to kickstart yourself in the CS domain!

Simple Sorting algorithm learning notes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nuwan Zen

Nuwan Zen

Sometimes A software Engineer, sometimes a support engineer, sometimes a devops engineer, sometimes a cloud engineer :D That’s how the this life goes!

More from Medium

Local variables with “var” since Java 10

What is java?

Working with Java Variables

Title image

Learn to use Spring Boot Initializr