Share on Google+Share on Google+

java.lang.String.endsWith(String str)

endsWith() method is a string class method in Java.

endsWith() method is a string class method in Java.

This is a simple endswith() java example, that check if the assigned string ends with the given string or not. If the given string does not ends with the given specific string(suffix) it will return False otherwise True.

Syntax of endsWith() method in Java

boolean endsWith(String suffix)

A simple Examples:

public class Example
public static void main(String[] args)
String str1 = "Java Programming Language";
String str2 = "Java application programming";

// will check if the given string ends with "ng" or not
String strendswith = "ng";

// checking the condition
boolean ends1 = str1.endsWith(strendswith);
boolean ends2 = str2.endsWith(strendswith);

// display the output
System.out.println("\"" + str1 + "\" ends with " +
"\"" + strendswith + "\"? " + ends1);
System.out.println("\"" + str2 + "\" ends with " +
"\"" + strendswith + "\"? " + ends2);

the Output is:
"Java Programming Language" ends with "ng"? false
"Java application programming" ends with "ng"? true


Posted on: March 17, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: java.lang.String.endsWith(String str)  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image