Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - String next() method



next() method is called by the ++ operator for the class String. It increments the last character in the given String.

Syntax

String next()

Parameters

NA

Return Value

The new value of the string.

Example - Use of next() method on String objects

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

Example.groovy

class Example { 
   static void main(String[] args) { 
      String a = "Hello World"; 
      println(a.next());         
   } 
}

Output

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

Hello Worle

Example - Use of next() method on String literal

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

Example.groovy

class Example { 
   static void main(String[] args) { 
      println("Hello World".next());         
   } 
}

Output

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

Hello Worle

Example - Use of next() method with Single Char String

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

Example.groovy

class Example { 
   static void main(String[] args) { 	      
      println("A".next());
	  println("a".next());
   } 
}

Output

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

B
b
groovy_strings.htm
Advertisements