Easy Tutorial
❮ Java Stack Class Java Scanner Class ❯

Java startsWith() Method

Java String Class


The startsWith() method is used to check if a string starts with the specified prefix.

Syntax

public boolean startsWith(String prefix, int toffset)

or

public boolean startsWith(String prefix)

Parameters

Return Value

Returns true if the string starts with the specified prefix; otherwise returns false.

Example

public class Test {
    public static void main(String args[]) {
        String Str = new String("www.tutorialpro.org");

        System.out.print("Return Value :" );
        System.out.println(Str.startsWith("www") );

        System.out.print("Return Value :" );
        System.out.println(Str.startsWith("tutorialpro") );

        System.out.print("Return Value :" );
        System.out.println(Str.startsWith("tutorialpro", 4) );
    }
}

The above program execution results are:

Return Value :true
Return Value :false
Return Value :true

Java String Class

❮ Java Stack Class Java Scanner Class ❯