Java String startsWith()

 Posted On  | Yashwant Chavan 

In this tutorial you will learn how to use String.startsWith(String prefix) method. Tests if this string starts with the specified prefix value. It returns true if string starts with specified prefix, otherwise returns false value.

Refer below steps

  • boolean java.lang.String.startsWith(String prefix) method tests if this string starts with the specified prefix.
  • Returns true if string starts with specified prefix, false otherwise

Java String.startsWith(String prefix) method example

package com.technicalkeeda.app;

public class StringStartsWith {

    public static void main(String args[]) {

        String str = "technicalkeeda";
        System.out.println("startsWith tech ? " + str.startsWith("tech"));
        System.out.println("startsWith Tech ? " + str.startsWith("Tech"));
        System.out.println("startsWith hello ? " + str.startsWith("hello"));
        System.out.println("startsWith technicalkeeda ? " + str.startsWith("technicalkeeda"));

    }
}

Output

startsWith tech ? true
startsWith Tech ? false
startsWith hello ? false
startsWith technicalkeeda ? true


Promote your Blog, Website, or services on technicalkeeda.com, My paypal id: yashwantchavan@gmail.com

Payment will be accepted through paypal only.


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0199 seconds.