Groovy : Find Index of Element in Map
Groovier way of finding index of element from Map. It can be obtained with findIndexOf Method, which accepts closure as argument.
Map map=["groovy":1,"grails":2,"index":3,"element":4] assert 3 == map.findIndexOf{it.key=="element"} assert 0 == map.findIndexOf{it.value==1}
That makes two of us.
Plus you can always sort map before using index.
I strongly don’t recommend you rely on index of an element in a collection that doesn’t enforce order explicitly