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