我有以下Groovy Map,
def mymap=["TXT_TXT":1,"IMG_TXT":2,"TXT_IMG":3,"IMG_IMG":4]
如何在此地图中找到元素的索引?
答案 0 :(得分:7)
使用findIndexOf方法如下:
def mymap=["TXT_TXT":1,"IMG_TXT":2,"TXT_IMG":3,"IMG_IMG":4]
assert 3 == mymap.findIndexOf{it.key=="IMG_IMG"}
assert 0 == mymap.findIndexOf{it.value==1}