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

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

String Start with Example

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