How to find if a string starts with a particular word – JAVA ?

By | June 29, 2011

Hi,

In order to find whether a given string starts with a particular string or not in JAVA, use the following code.


public class Main {

  public static void main(String[] args) {

    String urStr = "Coderz Heaven";

    if (urStr.startsWith("Coderz")) {

      System.out.println("Yes! Your string starts with Coderz");

    }

    else {

      System.out.println("No!");

    }

  }

}

Leave a Reply

Your email address will not be published. Required fields are marked *