Lambda
Lambda
• @FunctionalInterface annotation is
applicable (Optional)
Functional Interface
Abstract method
Lambda Expression
Syntax Description
Takes no argument and executes the given statement(s) in
( ) -> { statements }
lambda expression’s body
Takes argument(s) and executes the given statements in
(Parameters) -> { statements }
lambda expression’s body
Custom Functional interface Example
Abstract method
Lambda Expression:
Implementation of functional
interface’ abstract method
Build In Functional Interfaces:
• Predicate
• Consumer
• Function
• BiPredicate
• BiConsumer
• BiFunction
Build in Functional Interface: Predicate
• Represents a function which takes one argument (any object) and returns boolean
Abstract method
Predicate Interface Example
• Represents a function which takes one argument (any object) and does not return a value
Abstract method
Consumer Interface Example
Lambda Expression:
Implementation of Consumer
interface’s abstract method
Build in Functional Interface: Function
• Represents a function which takes one argument (any object) and return a value (any object)
Abstract method
Function Interface Example
Lambda Expression:
Implementation of function
interface’s abstract method
Build in Functional Interface: BiPredicate
• Represents a function which takes two arguments (any objects) and returns boolean
Abstract method
BiPredicate Interface Example
Lambda Expression:
Implementation of BiPredicate
interface’s abstract method
Build in Functional Interface: BiConsumer
• Represents a function which takes two argument (any object) and does not return a value
Abstract method
BiConsumer Interface Example
Lambda Expression:
Implementation of
BiConsumer interface’s
abstract method
Build in Functional Interface: BiFunction
• Represents a function which takes two arguments (any objects) and return a value (any object)
Abstract method
BiFunction Interface Example
Lambda Expression:
Implementation of
BiPredicate interface’s
abstract method
Stream
Stream
• Stream is a method that takes inputs from a data structure ( Array & Collection )
• After calling the stream() function from an Array/Collection, we can access to the
methods of stream