We can transform all elements of a list and create a new list using the map()
function :
// Syntax :
coll.map { /* Return new value */ }
Example :
fun main() {
// Create list of squares of numbers from a list
val nums = 1..5
val squares = nums.map { it * it }
println(squares)
}
// Output : [1, 4, 9, 16, 25]