Groovy – Lists plus()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
List composed

Creates a new List composed of the elements of the original together with those specified in the collection.

Syntax

List plus(Collection collection)

Parameters

Collection – The collection of values to add to the list.

Return Value

New list of values.

Example

Following is an example of the usage of this method −

class Example { 
   static void main(String[] args) { 
      def lst = [11, 12, 13, 14]; 
      def newlst = []; 
      
      newlst = lst.plus([15,16]); 
      println(newlst); 
   } 
}

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

[11, 12, 13, 14, 15, 16]

Previous Page:-Click Here

Leave a Reply