How to debug lambda expressions in Java?


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

Updated on: 10-Jul-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements