X

Lambdas with Collections and Method References

How to use lambda expressions with existing Java APIs and with method referencing to increase code reuse and improve productivity.

Java 8 first introduced the Stream API with the Java Collections Framework. In this new article, Mohan Basavarajappa dives into the package Java.util.function, collection classes and stream references use cases for day-to-day programming.  

To show how to combine collection classes with lambda expressions, Mohan describes four examples: create an array with a collection and perform operations on those collections; use client code to perform an operation on the collection; remove elements from a collection; and evaluate elements with Consumer API. 

Method references can complement lambda expressions. Mohan demonstrated how to leverage existing implementations while using functional interfaces and also how to use method references as a substitute for lambda expressions.

His collections and method referencing examples cover situations in which lambda expressions can be used with existing Java APIs to write better code and take advantage of implementations that are readily available with Java 8, as well as cases where functional interfaces are accepted as parameters to inject existing implementations for libraries using functional programming.

This article follows “Getting Started with Lambda Expressions” article,  explaining the basics of lambda expressions and their usage. 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.