Finding the key in a map, given the value

前端 未结 5 2701
迷失自我
迷失自我 2021-02-20 16:57

Hi I have a map like this :

[this:0, is:1, a:2, file:3, anotherkey:4, aa:5]

I wish I could find the key\'s given the value

5条回答
  •  你的背包
    2021-02-20 17:33

    def expect = 5
    def m = ['this':0, is:1, a:2, file:3,  aa:5]
    def r = m.collectMany{ k,v -> (v == expect) ? [k] : []}
    
    // Result: [aa]
    

提交回复
热议问题