Tsallaka zuwa abun ciki
Justice Tech School

Lambdas

A lambda is a short anonymous function: (a, b) -> a + b.

Example
import java.util.function.*;
public class Main {
  public static void main(String[] args) {
    Function<Integer, Integer> dbl = x -> x * 2;
    BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
    Runnable r = () -> System.out.println("run");
    r.run();
    System.out.println(dbl.apply(4) + " " + add.apply(1, 2));
  }
}

Result

run
8 3

Exercise

Arrow symbol.

x  x * 2

Quiz Test

What is a lambda?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.