Scala Map foreach

后端 未结 7 1952
刺人心
刺人心 2021-01-31 14:15

given:

val m = Map[String, Int](\"a\" -> 1, \"b\" -> 2, \"c\" -> 3)
m.foreach((key: String, value: Int) => println(\">>> key=\" + key + \",          


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 14:49

    oops, read the doco wrong, map.foreach expects a function literal with a tuple argument!

    so

    m.foreach((e: (String, Int)) => println(e._1 + "=" + e._2))
    

    works

提交回复
热议问题