Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - String minus(String value) method



minus() method removes the value part of the String.

Syntax

String minus(Object value)

Parameters

value − the string object which needs to be removed

Return Value

This method returns the new string minus the value string.

Example - Use of minus() method on String objects

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

Example.groovy

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

Output

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

Hello 
 World

Example - Use of minus() method on String literal

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

Example.groovy

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

Output

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

Hello 
 World

Example - Use of minus() method with non-existing substring

Following is an example of the usage of minus() method. Here as value string is not present in the main string, result is main string as it is.

Example.groovy

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

Output

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

Hello World
groovy_strings.htm
Advertisements