Retrieve value in map by key in Groovy
<pre><code>def text= '''&lt;Rollback&gt;  &lt;Kits&gt;
&lt;Kit ServerName='ust1twastool01a'&gt;
  &lt;Backup&gt;2016-10-18_20_34-46-_server-21.000.409_client-21.000.407.zip&lt;/Backup&gt;
  &lt;Backup&gt;2016-10-18_21_57-33-_server-21.000.409_client-21.000.407.zip&lt;/Backup&gt;
  &lt;Backup&gt;2016-10-19_02_40-03-_server-21.000.413_client-21.000.407.zip&lt;/Backup&gt;
  &lt;Backup&gt;2016-10-19_13_58-36-_server-21.000.413_client-21.000.407.zip&lt;/Backup&gt;
  &lt;Backup&gt;2016-10-20_03_14-34-_server-21.000.413_client-21.000.407.zip&lt;/Backup&gt;
&lt;/Kit&gt;
&lt;Kit ServerName='another_server'&gt;
  &lt;Backup&gt;123123.zip&lt;/Backup&gt;
  &lt;Backup&gt;321321.zip&lt;/Backup&gt;
&lt;/Kit&gt;
&lt;/Kits&gt;&lt;/Rollback&gt;'''


def xml = new XmlSlurper().parseText(text)
def map = [:]
i = 0
xml.Kits.Kit.each{node-&gt;
    def list = []
    node.Backup.each{kit-&gt;
    list.add(kit)
}
map.put(node.@ServerName, list)
}

print map // print map with all keys and values

// Somehow, it's not working ...
print map['ust1twastool01a']

def map2 = ['1':["abc","123"], '2':["bcd", "456"]]
print map2['1']
</code></pre>

<p>​
I have been annoyed by the above code for almost the day. I don't understand why I can't get value by map['ust1twastool01a'].</p>

<p>I attached a screenshot from a console, it shows that map is not empty but just can't get its value by key. map2 is just control group as it has the similar structure to map string as key and list as value<a href="https://i.stack.imgur.com/QHtbF.png" rel="nofollow"><img src="https://i.stack.imgur.com/QHtbF.png" alt="enter image description here"></a></p>