`map` transforms every element of a collection by applying a function and collecting its return values into a new collection. The output keeps the input’s element count, but its element type or representation can change. Use it instead of manual iteration when each item needs the same conversion. section 6.1.1 section 6.1
Square every number
```kotlin val numbers = listOf(1, 2, 3, 4) println(numbers.map { it * it }) // [1, 4, 9, 16] ``` The lambda receives each element as `it`; its result becomes the corresponding element of the new list. `map` transforms rather than removes values, unlike `filter`, which retains only elements whose predicate is true. section 6.1.1
fun main() {
val list = listOf(1, 2, 3, 4)
println(list.map { it * it })
// [1, 4, 9, 16]
}
Follow the input-to-output transformation: each number is replaced by its square in a newly collected result. section 6.1.1
Transforming objects is a common use: `people.map { it.name }` produces names rather than `Person` objects. A member reference can make the same operation shorter: `people.map(Person::name)`. Calls can be chained, such as filtering people by age before mapping the remaining people to names. section 6.1.1 section 1.2.3
Use related collection operations according to the result needed:
- Use `filter` to select matching elements without changing their type. section 6.1.1
- Use `mapIndexed` when the transformation needs both an element and its index. section 6.1.1
- Use `mapValues` to transform values in a map while retaining its keys. section 6.1.1
- Use `flatMap` for nested collections when transformation and flattening belong in one step. section 6.3
`map` belongs to a shared vocabulary of Kotlin collection operations used with lambdas. It works with the same Java collection classes Kotlin uses on the JVM, so collection values can be exchanged with Java code without conversion. For chains with many operations, sequences can avoid creating intermediate collections while using the same operations. section 3.1 section 6.3



















