- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if the string ends with specific substring in Java?
A String is an object that represents an immutable sequence of characters and cannot be changed once created. The java.lang.String class can be used to create a string object.
We can use the endsWith() method of String class to check whether a string ends with a specific string or not, it returns a boolean value true or false.
Syntax
public boolean endsWith(String prefix)
Example
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!"); } } }
Output
Ends with the specified word!
Advertisements
To Continue Learning Please Login
Login with Google