Groovy - reverse()


Advertisements

Create a new List that is the reverse the elements of the original List.

Syntax

List reverse()

Parameters

None

Return Value

The reversed list.

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 revlst = lst.reverse(); 
      println(revlst); 
   } 
}

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

[14, 13, 12, 11] 
groovy_lists.htm
Advertisements