Note: I am not referring to the java enum
/enumeration
but rather how to associate the ordinal/index of each element in a collection with the element. I am looking for the equivalent of :
scala :
(1 to 10).zipWithIndex.foreach{ case (obj,i) => println(s"Obj[$i]=$obj") }obj.length}
python :
for i,obj in enumerate(range(1,11)):
print(f"obj[{i}]={str(obj)}")
javascript :
var myList= [...Array(10)].map((_,i) => 1+i)
myList.forEach( (obj,i) => console.log(`obj[${i}]=${obj}`))
It does not appear that java has a perfect/simple analog? Do we need to use the somewhat awkward manual zip
of lists like in this question? How to zip two Java Lists ? What might be the most concise way to associate indices with the list elements?