Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - String plus(String value) method



plus() method appends the value to the String.

Syntax

String plus(Object value)

Parameters

value − the string object to be appended.

Return Value

This method returns the new string plus the value string.

Example - Use of plus() method on String objects

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

Example.groovy

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

Output

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

Hello World!
Hello World!!

Example - Use of plus() method on String literal

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

Example.groovy

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

Output

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

Hello World!
Hello World!!

Example - Use of plus() method on empty strings

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

Example.groovy

class Example { 
   static void main(String[] args) { 	
      String a = "";
      println(a.plus("TutorialPoint"));
   } 
}

Output

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

TutorialPoint
groovy_strings.htm
Advertisements