Thursday, 8 June 2017

Java Tutorial: Lambda expression in java[Lambda expression with multiple statements] ~ foundjava


Click here to watch in Youtube :
https://www.youtube.com/watch?v=JBhLlDqPUWU&list=UUhwKlOVR041tngjerWxVccw



LambdaDemo.java

@FunctionalInterface
interface Message
{
    String displayMessage(String strValue);
}

/**
 * Java Lambda Expression Example: Multiple Statements
 *
 */
public class LambdaDemo
{

    public static void main(String[] args)
    {
        /*
         * We can pass multiple statements in lambda expression.
         */
        Message msg = (strValue) -> {
            String str1 = "Welcome to ";
            String str2 = str1 + strValue;
            return str2;
        };
        System.out.println(msg.displayMessage("India."));
    }

}
Output
Welcome to India.
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LambdaDemo_multi_statement_App.zip?attredirects=0&d=1

No comments:

Post a Comment