How can I use map and receive an index as well in Scala?

前端 未结 8 1827
轮回少年
轮回少年 2020-12-12 23:07

Is there any List/Sequence built-in that behaves like map and provides the element\'s index as well?

8条回答
  •  醉酒成梦
    2020-12-12 23:55

    If you require searching the map values as well (like I had to):

    val ls = List("a","b","c")
    val ls_index_map = ls.zipWithIndex.toMap 
    

提交回复
热议问题