Table of Contents
String’s endWith method checks if String ends with specific suffix. It returns boolean datatype.
When you run above program, you will get below output:
Method syntax:
1 2 3 |
public boolean endsWith(String suffix) |
String endsWith Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package org.arpit.java2blog; public class StringEndsWithExample { public static void main(String[] args) { String str = "java2blog"; if (str.endsWith("blog")) { System.out.println("String ends with blog"); } else { System.out.println("String does not end with blog"); } if (str.endsWith("BLOG")) { System.out.println("String ends with BLOG"); } else { System.out.println("String does not end with BLOG"); } } } |
1 2 3 4 |
String ends with blog String does not end with BLOG |
Please note that endsWith method is case sensitive as you can see in above example
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.