java.lang.String endsWith()
Description :
This java tutorial shows how to use the endsWith() method of java.lang.String class. This method returns booelan data type. The endsWith() method of String class generally checks if the end of the String is equivalent to String suffix method argument.
Method Syntax :
public boolean endsWith(String suffix)
Parameter Input :
DataType | Parameter | Description |
---|---|---|
String | suffix | the string argument which we want to check at the end of our String |
Method Returns :
This method returns boolean. Method returns true if the character sequence specified on our parameter matches the end characters of our String.
Java Code Example :
This example source code demonstrates the use of endsWith() method of String class. Basically this source code just check if the String ends with our suffix method argument.
package com.javatutorialhq.java.tutorial.string; /* * Example java source code that shows how to use endsWith method */ public class StringEndsWith { public static void main(String[] args) { String stringExample = "This is sample string"; // Check if the string is ends with ing if(stringExample.endsWith("ing")){ System.out.println("String ends with 'ing'"); } else{ System.out.println("It does not match at all"); } } }
Sample Output :
Running the endsWith() method example source code of java.lang.String class will give you the following output