DEV Community

Vrushali
Vrushali

Posted on

map() in Kotlin vs Dart (Beginner Friendly)

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

Top comments (0)