String Handling – startsWith( )

startsWith( )

Syntax

boolean startsWith(String str);

 

startsWith ( ) is  standard method of String, it is used to compare the given string with the starting characters of invoking object, if the given string is matched with the starting characters of invoking object then it will return true otherwise it will return false it is case sensitive method.

 

class Example

{

public static void main (String arg[ ])

{

String s1 = “Code project”;

boolean b = s1.startsWith(“Co”);

System.out.println(b);

System.out.println(s1.startsWith(“tions”));

System.out.println (s1.startsWith(“sita”));

System.out.println (s1.startsWith(“Code project”));

}

}

output :-

true

false

false

true

Leave a Reply

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