Groovy - Maps size()


Advertisements

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 
groovy_maps.htm
Advertisements