Home Java Beginners String Start with Example
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

String Start with Example

Advertisement
In this section, you will learn how to check the given string that start from the specified character in java. The following program checks the started string with "Wel". If you use startsWith() function it will return 'true' and display a message "The

String Start with Example

     

In this section, you will learn how to check the given string that start from the specified character in java. The following program checks the started string with "Wel". If  you  use startsWith() function it will return 'true' and display a message "The given string is start with Wel" otherwise it will show "The given string is not start with Wel". 

Description of code:

startsWith(String start):
This is a Boolean type method that returns either 'true' or 'false'. It checks the given string that begins with specified string in the beginning. It takes a string type parameter such as:

    start: This is the string that starts.

Here is the code of program:

import java.lang.*;

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

Download this example.

Output of program:

C:\vinod\Math_package>javac StrStartWith.java

C:\vinod\Math_package>java StrStartWith
String start with example!
Given String : Welcome to RoseIndia
Start with : Wel
The given string is start with Wel
Advertisements

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: March 13, 2008

Related Tutorials

Ask Questions?    Discuss: String Start with Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
harish.j
July 4, 2012
c,c++,java

it is used in program language
DMCA.com