26

We can create lambda functions like this:

Function<Integer, String> getLambda = (a) -> new String("given value is "a);

I have a scenario where I need to take 2 values in a parameter. How can I accomplish that using Function?

Example:

getLamda(10,20); // I know this line will give error. How can I acheive this? 
0

2 Answers 2

41

This is done using a BiFunction<T,U,R>. Following is an example of a BiFunction returning the character at the specified index of a String:

BiFunction<String, Integer, Character> charAtFunction = (string, index) -> string.charAt(index);
Sign up to request clarification or add additional context in comments.

Comments

9

Try :

BiFunction<Integer, Integer, String> lambda = (a, b) -> ("Given values are " + a + ", " + b);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.