How to debug lambda expressions in Java?

Java 8Object Oriented ProgrammingProgramming

The lambda expression composed of two parts, one is an argument and another one is code or expression. These two parts have separated by an arrow operator "->". We can use different IDE's like Netbeans, IntelliJ, and Eclipse to debug the lambda expressions in Java. It is always possible to create multi-line lambda expressions and use print statements to display the values of a variable. The debugger can also provide additional information about the state of a java program. It allows some variables to be modified while the debugger is executing.

Syntax

(parameters) -> expression
  or
(parameters) -> { statements; }

Example

import java.util.*;

public class LambdaDebugTest {
   public static void main(String args[]) {
      List<Strng> list = Arrays.asList("jai", "adithya", "raja");
      list.stream()
          .map(s -> s + " - " + s.toUpperCase())  // Convert to upper case using lambda
          .forEach(s -> System.out.println(s));   // To print 's' using lambda
   }
}

Output

jai - JAI
adithya - ADITHYA
raja - RAJA
raja
Published on 16-Dec-2019 14:46:06
Advertisements