Groovy – Maps size()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
mappings

Returns the number of key-value mappings in this Map.

Syntax

int size()

Parameters

None.

Return Value

The size of the map.

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.size()); 
		
      mp.put("TopicID","1"); 
      println(mp.size()); 
   } 
} 

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

2 
3 

Previous Page:-Click Here

Leave a Reply