Groovy – put()

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

Associates the specified value with the specified key in this Map. If this Map previously contained a mapping for this key, the old value is replaced by the specified value.

Syntax

Object put(Object key, Object value)

Parameters

  • Key โ€“ The key to be put in the map
  • Value โ€“ The associated value for the key

Return Value

The returned key-value pair which is inserted.

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

When we run the above program, we will get the following result โˆ’

[TopicName:Maps, TopicDescription:Methods in Maps, TopicID:1]

Previous Page:-Click Here

Leave a Reply