Groovy - endsWith()



Tests whether this string ends with the specified suffix.

Syntax

Boolean endsWith(String suffix)

Parameters

  • Suffix – The suffix to search for

Return Value

This method returns true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise. Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the equals(Object) method.

Example

Following is an example of the usage of this method −

class Example {
   static void main(String[] args) {
      String s = "HelloWorld";
		
      println(s.endsWith("ld"));
      println(s.endsWith("lo"));
      println("Hello".endsWith("lo"));
   } 
} 

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

true
false 
true 
groovy_strings.htm
Advertisements