Syntax

Kotlin Filter and Map Syntax

In Kotlin, filter and map: transforms a collection — nums.filter { it > 0 }.map { it * 2 }

Quick Answer

Syntax
nums.filter { it > 0 }.map { it * 2 }
KotlinSyntax

Filter and Map

Code example
nums.filter { it > 0 }.map { it * 2 }

Transforms a collection.

Learn More

How to filter and map in Kotlin

  1. Open your Kotlin file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Kotlin Filter and Map Syntax

Use nums.filter { it > 0 }.map { it * 2 }.

Related Syntax References

Frequently asked questions

What is the Kotlin syntax for filter and map?

Use this pattern: nums.filter { it > 0 }.map { it * 2 }

Can I copy this Kotlin code example?

Yes. Use Copy code and adapt the example to your program.

Is this Kotlin syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify