Wednesday 8 February 2017

Java String endsWith() Method



The endsWith() Method:

  The endsWith() method does just the opposite to startWith(), i.e. it checks if a given piece of String ends with a specific String. The general form is:

Boolean endsWith(String str)

For example:

“Learning Java is fun”.endsWith(“fun”);

 Will return true.
 Consider the following example:

EndsWithTest.java


 class EndsWithTest
 {
  public static void main(String arg[])
  {
    String str="Learning Java is fun";
    System.out.print("String str ends with funn:");
   System.out.println(str.endsWith("fun"));
    System.out.print("String str start with Java:");
    System.out.println(str.startsWith("Java"));

  }
 }

The output generated by the above program is:

String str ends with funn:true
String str start with Java:false

 Next Topic Shahbaz

0 comments:

Post a Comment

Powered by Blogger.

Stats