startsWith():This function returns result in Boolean expression. If the given value matches with the value specified as argument then the result is true otherwise false.
Syntax:Stringname.startsWith(Value);
endsWith():This function also returns result in Boolean.If the given value matches with the value specified as argument then the result is true otherwise false.
Syntax:Stringname.endsWith(Value);
WAP in Java to show the use of startsWith() and endsWith() String functions in Java:
class dony{
public static void main(String args[])
{
String str=new String("Hello to all");
System.out.println(str.startsWith("to"));
System.out.println(str.endsWith("all"));
System.out.println(str);
}
}
The output is:
0 comments: