top of page
pchintan21

Streamlining Your Selenium Tests with Java Streams and Lambdas


Lambdas

A lambda expression is a microcode that takes in parameter(s) and returns a value. Lambda expressions are similar to methods, but they are anonymous and they can be implemented right in the body of a method.


Lambdas Syntax

1. The simplest lambda expression contains a single parameter and an expression:

parameter->expression

2. To use more than one parameter, wrap them in parentheses:

(parameter1, parameter2)->expression

Example

Use a lambda expression in the ArrayList's forEach() method to print every item in the list:


import java.util.ArrayList;
public class Main{
public static void main(String[] args){
ArrayList<Integer> numbers =new ArrayList<Integer>();     numbers.add(5);     
numbers.add(9);     
numbers.add(8);     
numbers.add(1);
numbers.forEach( (n) -> { System.out.println(n); } );
 }
}

Streams

Implementation of Java Streams and Lambdas in Selenium WebDriver

Conclusion



15 views0 comments

Recent Posts

See All

Comments


bottom of page