Groovy – containsKey()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
contain key

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

Previous Page:-Click Here

Leave a Reply