Menu

Post image 1
Post image 2
1 / 2
0

map() in Kotlin vs Dart (Beginner Friendly)

DEV Community·Vrushali·about 1 month ago
#OXBwgBlN
Reading 0:00
15s threshold

Vrushali

Ever wondered what map() actually does? 🤔

Let’s break it down in the simplest way possible 👇


🧠 What is map()?

map() is used to transform a list into another list.

👉 It takes each item

👉 Applies some logic

👉 Returns a new list

🟣 Kotlin Example

val numbers = listOf(1, 2, 3)

val doubled = numbers.map {
    it * 2
}

println(doubled) // [2, 4, 6]

Enter fullscreen mode Exit fullscreen mode

🟣 Dart Example

var numbers = [1, 2, 3];

var doubled = numbers.map((n) => n * 2).toList();

print(doubled); // [2, 4, 6]

Enter fullscreen mode Exit fullscreen mode

Read More