Groovy - sort()



Returns a sorted copy of the original List.

Syntax

List sort()

Parameters

None

Return Value

The sorted list.

Example

Following is an example of the usage of this method −

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

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

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