Groovy : Find Index of Element in Map

10 / Nov / 2011 by Hitesh Bhatia 2 comments

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}

FOUND THIS USEFUL? SHARE IT

comments (2)

Leave a comment -