val arr = List(8, 15, 22, 1, 10, 6, 18, 18, 1) arr.zipWithIndex.map(_._2) works and give me index of the elements in the list .How to access the index and the element as part of the map function
3 Answers
val arr = List(8, 15, 22, 1, 10, 6, 18, 18, 1)
arr.zipWithIndex.map(zippedList => (zippedList._1, zippedList._2))
if you want to access the element it's ._1 and index ._2
you can also use this:
arr.zipWithIndex.map {
case (x, y) => print(x, y)
}
and so the operation on x and y what ever you want to do.
1 Comment
boredmgr
Thanks Raman. I was trying to destruct the inside the parameter list itsef.