Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - Range isReverse() method



isReverse() method checks a range if it is reversed range, iterating backwards.

Syntax

boolean isReverse()

Parameters

NA

Return Value

Returns boolean value of true or false on whether the range is reversed.

Example - Checking a range of numbers

Following is an example of the usage of isReverse() method.

Example.groovy

class Example { 
   static void main(String[] args) { 
      // range of numbers
      def array = 1..10;		
      println(array.isReverse());

      // range of numbers in reversed form
      def array1 = 10..1;		
      println(array1.isReverse());	  
   } 
}

Output

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

false
true

Example - Checking a range of characters

Following is an example of the usage of isReverse() method.

Example.groovy

class Example { 
   static void main(String[] args) { 
      // range of characters
      def array = 'a'..'z';		
      println(array.isReverse());

      // range of characters in reversed form
      def array1 = 'z'..'a';		
      println(array1.isReverse());	  
   } 
}

Output

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

false
true

Example - Checking a range of special characters

Following is an example of the usage of isReverse() method.

Example.groovy

class Example { 
   static void main(String[] args) { 
      // range of special characters
      def array = '&'..'!';		
      println(array.isReverse());

      // range of characters in reversed form
      def array1 = '!'..'&';		
      println(array1.isReverse());	  
   } 
}

Output

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

true
false
groovy_ranges.htm
Advertisements