AWS

Groovy : Find Index of Element in Map

1 min read
Share:

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]

comments ( 2 )

Leave a Reply

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