Home Tutorials Java StringExamples java.lang.String.endsWith(String str)



java.lang.String.endsWith(String str)
Posted on: March 17, 2005 at 12:00 AM
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

Related Tags for java.lang.String.endsWith(String str):


More Tutorials from this section

Ask Questions?    Discuss: java.lang.String.endsWith(String str)  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.