A string is an object that represents an immutable sequence of characters and cannot be changed once created. String objects can be created using the java.lang.String class.
We can use the endsWith() method of the String class to check whether a string ends with a specific string , it returns a Boolean Value true or false.
public boolean endsWith(String prefix)
public class StringEndsWithSubStringTest { public static void main(String[] args) { String str = "WelcomeToTutorialsPoint"; if(str.endsWith("Point")) { System.out.println("Ends with the specified word!"); } else { System.out.println("Does not end with the specified word!"); } } }
Ends with the specified word!
The above is the detailed content of How to check if a string ends with a specific substring in Java?. For more information, please follow other related articles on the PHP Chinese website!