﻿---
title: Lambdas
description: Lambda expressions and method references work the same as in Java. You can make method references to functions within the script with this, for example...
url: https://www.elastic.co/elastic/docs-builder/docs/2407/reference/scripting-languages/painless/painless-lambdas
products:
  - Painless
---

# Lambdas
Lambda expressions and method references work the same as in [Java](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.md).
```java
list.removeIf(item -> item == 2);
list.removeIf((int item) -> item == 2);
list.removeIf((int item) -> { item == 2 });
list.sort((x, y) -> x - y);
list.sort(Integer::compare);
```

You can make method references to functions within the script with `this`, for example `list.sort(this::mycompare)`.