Writing a Simple Lambda Expression - Java Lambda Stream

Java examples for Lambda Stream:Lambda

Introduction

A lambda expression is an anonymous block of code containing statements and returns a result.

Demo Code

public class Main {

  public static void main(String[] args) {
    // Invoke the lambda, passing a parameter named "text" to the
    // hello() method, returning the string
    HelloType helloLambda = (String text) -> {
      System.out.println("Hello " + text);
    };/* ww w  .j  a  v  a2  s .  com*/
    // Invoke the method call
    helloLambda.hello("Lambda");
  }
}

/**
 * Functional Interface
 */

interface HelloType {
  /**
   * Function that will be implemented within the lambda
   * 
   * @param text
   */
  void hello(String text);
}

Result


Related Tutorials