Create functional interface to use of Lambda Expressions - Java Lambda Stream

Java examples for Lambda Stream:Lambda

Introduction

The following lines of code demonstrate a functional interface that contains a single method declaration.

Demo Code

public class Main {

  public static void main(String[] args) {
    ReverseType newText = (testText) -> {
      String tempStr = "";
      for (String part : testText.split(" ")) {
        tempStr += new StringBuilder(part).reverse().toString() + " ";
      }/*from w ww .  j  ava 2 s  .co m*/
      return tempStr;
    };

    System.out.println(newText.reverse("HELLO WORLD"));
  }
}

@FunctionalInterface
interface ReverseType {

  String reverse(String text);
}

Result


Related Tutorials