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.

[groovy]

Map map=["groovy":1,"grails":2,"index":3,"element":4]
assert 3 == map.findIndexOf{it.key=="element"}
assert 0 == map.findIndexOf{it.value==1}

[/groovy]

FOUND THIS USEFUL? SHARE IT

comments (2)

Leave a Reply

Your email address will not be published. Required fields are marked *