Home Java Beginners String End with Example

 
 

Share on Google+Share on Google+

String End with Example

Advertisement
This section tells you, how to determine the given string ends with specified string.

String End with Example

     

This section tells you, how to determine the given string ends with specified string. The following program helps you to check whether the given string starts with the specified string is true or false by applying endsWith() method and returns Boolean types values either 'true' or 'false'. If it returns 'true', it will display a message "The given string is end with RoseIndia" otherwise it shows "The given string is not end with RoseIndia". 

Description of code:

endsWith(String end):
This is a Boolean type method that returns either 'true' or 'false'. It checks the given string that end with specified string in end. It takes string type parameter like:

    end: This is the string that is ended.

Here is the code of program:

import java.lang.*;

public class StrEndWith{
  public static void main(String[] args) {
  System.out.println("String end with example!");
  String str = "Welcome to RoseIndia";
  String end = "RoseIndia";
  System.out.println("Given String : " + str);
  System.out.println("End with : " + end);
  if (str.endsWith(end)){
  System.out.println("The given string is end with RoseIndia");
  }
  else{
  System.out.println("The given string is not end with RoseIndia");
  }
  }
}

Download this example.

Output of program:

C:\vinod\Math_package>javac StrEndWith.java

C:\vinod\Math_package>java StrEndWith
String end with example!
Given String : Welcome to RoseIndia
End with : RoseIndia
The given string is end with RoseIndia
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: June 8, 2007

Related Tutorials

Discuss: String End with Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com