Groovy - containsKey()



Does this Map contain this key?

Syntax

boolean containsKey(Object key)

Parameters

Key − The key used to search for.

Return Value

True or false depending on whether the key value is there or not.

Example

Following is an example of the usage of this method −

class Example { 
   static void main(String[] args) { 
      def mp = ["TopicName" : "Maps", "TopicDescription" : "Methods in Maps"] 
      println(mp.containsKey("TopicName")); 
      println(mp.containsKey("Topic")); 
   } 
}

When we run the above program, we will get the following result −

true 
false
groovy_maps.htm
Advertisements