Syntax
for((key, value) <- map){
}
Example
scala> val employeeNamesById = Map(1 -> "Ram", 2 -> "Gopi", 3 -> "Joel")
val employeeNamesById: scala.collection.immutable.Map[Int,String] = Map(1 -> Ram, 2 -> Gopi, 3 -> Joel)
scala> for((id, name) <- employeeNamesById){
| println(s"$id = $name")
| }
1 = Ram
2 = Gopi
3 = Joel
No comments:
Post a Comment