Get index of current element in a foreach method of Traversable?

前端 未结 4 810
南笙
南笙 2020-12-07 18:49

Suppose I have two arrays:

val ar1 = Array[String](\"1\", \"2\", \"3\")
val ar2 = Array[String](\"1\", \"2\", \"3\", \"4\")

Now for each e

4条回答
  •  一整个雨季
    2020-12-07 19:23

    I did not had the opportunity to test it, but this should do the trick:

    ar1.zip(ar2).foreach(x => println(x._1 + x._2))
    

提交回复
热议问题