groovy: safely find a key in a map and return its value

后端 未结 5 1740
我寻月下人不归
我寻月下人不归 2021-02-01 12:33

I want to find a specific key in a given map. If the key is found, I then want to get the value of that key from the map.

This is what I managed so far:

         


        
5条回答
  •  故里飘歌
    2021-02-01 13:23

    Groovy maps can be used with the property property, so you can just do:

    def x = mymap.likes
    

    If the key you are looking for (for example 'likes.key') contains a dot itself, then you can use the syntax:

    def x = mymap.'likes.key'
    

提交回复
热议问题