- Trending Categories
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
Java Program to check the end of a string
To check the end of a string, use the endsWith() method.
Let’s say the following is our string.
String str = "demo";
Now, check for the substring “mo” using the endsWith() method in an if-else condition.
if(str.endsWith("mo")) { System.out.println("The string ends with the word mo"); } else { System.out.println("The string does not end with the word mo"); }
The following is the complete example with output.
Example
public class Demo { public static void main(String[] args) { String str = "demo"; if(str.endsWith("mo")) { System.out.println("The string ends with the word mo"); } else { System.out.println("The string does not end with the word mo"); } } }
Output
The string ends with the word mo
- Related Articles
- Java Program to check the beginning of a string
- Java Program to remove whitespace from the beginning and end of a string
- C# Program to remove the end part of a string
- Java Program to Check if a String is Numeric
- Java program to check for URL in a String
- Java program to check string as palindrome
- Java program to check order of characters in string
- Java Program to Check if a string contains a substring
- Java Program to check whether one String is a rotation of another.
- Java program to check occurence of each character in String
- Java program to check occurence of each vowel in String
- Java program to check occurrence of each character in String
- Java program to check occurrence of each vowel in String
- Python Program to move numbers to the end of the string
- Java program to check if string is pangram

Advertisements