Tasty Lambdas in Java 8

If you ask my opinion about the most interesting feature added to a static type languages like Java, I would answer it is definitely ‘Lambda’.

Lambda expressions reduces lines of code while increasing the readability and expressiveness of the code. My friends know me as a huge fan of lambda expressions for years. I’ve always enjoy to code using lambda calculus.

Here, I want to show some magic you can do with lambda every day! I want to compare some lambda-less and lambda solutions:

Consider this array which contains some cars with their relative mileages:

Scenario 1. A list of German cars

The lambda-less solution is:

And the solution with lambda:

Scenario 2. A list of Old car names

The lambda-less solution is:

And the solution with lambda:

Believe me, after learning how to use Lambda, it’s really hard to write code without it, even if you’re writing just some samples for your blog (me, now!). So, accept my apologize if I’m not going to write more lambda-less equivalent codes. Just try to guess what the lambda-less code would be!

Some more fun with Lambda


If you are more interested

In the case that I was successful to make you interested about Lambda(!), you can find more fun in the following links:

A good quick start from Oracle
Reference API for Stream
An article about Functional Programming in Java
Java 8 Tutorial: Lambda Expressions, Streams, and More


About the author

Mehran Davoudi

A former technology geek! Currently a mentor and software architect, working as a consultant for companies with large scale software development.
Why dvd? Read about me (uɒɹɥəɯ)!

View all posts


Leave a Reply

Your email address will not be published. Required fields are marked *