> ## Content Index
> Fetch the complete content index at: https://www.javahandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# What Are Lambda Expressions?
- URL: https://www.javahandbook.com/java-streams-api/what-are-lambda-expressions/
- Published: 2026-02-15T09:23:10.000Z
- Updated: 2026-02-15T09:23:10.000Z
- Description: This is an introductory lesson on lambda expressions. You will learn about the lambda operator, expression, syntaxes and more!
- Author: Gopi Gorantala
- Tags: #docs, #java-streams-api, Lambda Expressions

Lambdas were introduced in Java 8, which uses both new packages introduced from Java 8.

1\. `java.util.function` \- [Function](https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html?ref=javahandbook.com)

2\. `java.util.stream` \- [Stream](https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html?ref=javahandbook.com)

## Lambda operator

> The Lambda operator "->" introduces a Lambda expression.

The lambda expression syntax uses the lambda operator, shown below syntaxes.

```java
value -> value * 2;
```

```java
value -> { 
   return value * 2; 
}
```

## What is a lambda expression?

A lambda expression defines an anonymous function, or more correctly, an instance of an anonymous class that implements a functional interface.

Lambda expressions provide a clear and concise way of implementing a single-method interface using an expression. They help to iterate, filter, and extract data from the collection.

A lambda expression has the following syntax:

```java
(parameters) -> expression
```

Here, `parameters` refers to the function's input parameters and `expression` refers to the function's operation. For example, consider the following lambda expression:

```java
(x, y) -> x + y
```

This lambda expression takes two input parameters `x` and `y`, and returns their sum.

Lambda expressions can be used in various situations in Java, such as with functional interfaces, which contain a single abstract method. Using lambda expressions, you can pass behavior as a parameter to a method or store it in a variable.

For example, consider the following code:

```java
import java.util.Arrays;
import java.util.List;

public class PrintElements {
  public static void main(String[] args) {
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
    numbers.forEach((Integer value) -> System.out.println(value));
  }
}
```

Here, we create a list of numbers and use the `forEach` method to iterate over the list. We pass a lambda expression to the `forEach` method to print each value in the list.

Lambda expressions can also be used with streams to perform operations such as filtering and mapping on collections. Overall, lambda expressions are a powerful feature in Java that enable functional programming and make code more concise and expressive.

## What Are The Uses Of Lambda Expressions?

There are quite a few uses/advantages. Out of them, the most popular ones are

1. Provides the implementation of a functional interface.
2. Less code.

## Syntax

There are 3 ways we could re-write the syntax as follows.

### No Parameter

When there is no parameter for the lambda expressions, we use empty parenthesis to represent the lambda expression.

```java
() -> {
   // statements 
}
```

### One Parameter

We can remove the parenthesis when there is a single parameter in the lambda input. The following are valid syntaxes for a single parameter lambda expression.

```java
// All of the below single parameter lambda expressions are valid.

// first way
(ParameterType parameter1) -> {
   // single parameter statements 
}

// second way
(parameter1) -> {
   // single parameter statements 
}

// third way
parameter1 -> {
   // single parameter statements 
}
```

### More Than One Parameter

When more than one parameter is declared in the lambda input parenthesis, all of the following syntaxes are valid.

```java
// Both of the below single parameter lambda expressions are valid.

// first way
(ParameterType parameter1, ParameterType parameter2) -> {
   // multiple parameter statements 
}

// Another way
(parameter1, parameter2) -> {
   // multiple parameter statements 
}
```

This concludes the introduction of lambda expressions. In the next lessons, you will learn more about writing and using them.