The java string endsWith() method checks whether the string ends with a specified suffix.This method returns a boolean value true or false.
Signature:
public boolean endsWith(String suff)
Parameter:
suff- specified suffix part
Return:
true or false
Example:To show working of endsWith() method
// Java program to demonstrate // working of endsWith() method class Gfg1 { public static void main(String args[]) { String s = "Welcome! to GeeksforGeeks"; // Output will be true as s ends with Geeks boolean gfg1 = s.endsWith("Geeks"); System.out.println(gfg1); } } |
chevron_right
filter_none
Output:
true
// Java program to demonstrate // working of endsWith() method class Gfg2 { public static void main(String args[]) { String s = "Welcome! to GeeksforGeeks"; // Output will be false as s does not // end with "for" boolean gfg2 = s.endsWith("for"); System.out.println(gfg2); } } |
chevron_right
filter_none
Output:
false
// Java program to demonstrate // working of endsWith() method class Gfg3 { public static void main(String args[]) { String s = "Welcome! to GeeksforGeeks"; // Output will be true if the argument // is the empty string boolean gfg3 = s.endsWith(""); System.out.println(gfg3); } } |
chevron_right
filter_none
Output:
true
Recommended Posts:
- Java String toLowerCase() with examples
- Java String format() with examples
- Java String getChars() with examples
- Java String concat() with examples
- Java String join() with examples
- Split() String method in Java with examples
- ZoneOffset of(String) method in Java with Examples
- Java String subSequence() method with Examples
- String toString() Method in java with Examples
- Matcher replaceFirst(String) method in Java with Examples
- Matcher replaceAll(String) method in Java with Examples
- Matcher group(String) method in Java with Examples
- Matcher quoteReplacement(String) method in Java with Examples
- Matcher start(String) method in Java with Examples
- Matcher appendReplacement(StringBuilder, String) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



