java.util.function.Function is a functional interface as part of java.util.function package which is introduced in Java 8. It is an in-built Functional Interface. This function expects one argument and produces a result. In this post, we are going to see several implementations of Function Interface using different examples.

java.util.function.Function Interface in Java 8 with Examples...!!! Click To Tweet

Look at java.util.function.Function Javadoc description below:

Function_Signature_Java8_Techndeck

Function Interface contains 4 methods:

  1. apply

  2. compose

  3. andThen

  4. identity

Lets understand above mentioned methods thorough various examples:

Example 1. ‘apply’ method

Below example shows how to use ‘apply’ method of ‘Function’ interface using Lambda expression.

Output:

Example 2. ‘andThen’ & ‘compose’ methods

Below example shows how to use ‘andThen’ & ‘compose’ methods of ‘Function’ interface using Lambda expression.

Output:

Do you like this Post? – then check my other helpful posts:

Other Useful References: