[scala]val l = List(1,2,3,4,5)
val lAfterForEach = l.foreach(x => x * 10)
val lAfterMap = l.map(x => x * 10)
println(“Original List: ” + l)
println(“For each operates on each element, returns nothing:” + lAfterForEach)
println(“Map is like foreach but returns new post-processed list: ” + lAfterMap)[/scala]
output:
[bash]Original List: List(1, 2, 3, 4, 5)
For each operates on each element, returns nothing:()
Map is like foreach but returns new post-processed list: List(10, 20, 30, 40, 50)[/bash]