Groovy – sort()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
sorted

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]

Previous Page:-Click Here

Leave a Reply