Advertisement
public boolean startsWith(String st)
// startsWith() method of String.
class StringStartsWith
{
public static void main(String[] ar)
{
String str1= new String("Hello World");
System.out.println("String is " + str1);
boolean boo1 = str1.startsWith("He");
System.out.println("Does "+ str1 + " starts with He ? "+ boo1);
boolean boo2 = str1.startsWith("Hello");
System.out.println("Does "+ str1 + " starts with Hello ? "+ boo2);
boolean boo3 = str1.startsWith("World");
System.out.println("Does "+ str1 + " starts with World ? "+ boo3);
}
}
String is Hello World
Does Hello World starts with He ? true
Does Hello World starts with Hello ? true
Does Hello World starts with World ? false
// startsWith() method of String.
class StringStartsWith
{
public static void main(String[] ar)
{
String str1= new String("World Peace");
System.out.println("String is " + str1);
boolean boo1 = str1.startsWith("World");
System.out.println("Does "+ str1 + " starts with World ? "+ boo1);
boolean boo2 = str1.startsWith("world");
System.out.println("Does "+ str1 + " starts with world ? "+ boo2);
boolean boo3 = str1.startsWith("WORLD");
System.out.println("Does "+ str1 + " starts with WORLD ? "+ boo3);
}
}
String is Hello World
Does World Peace starts with World ? true
Does World Peace starts with world ? false
Does Hello World starts with WORLD ? false
Advertisement
// startsWith() method of String.
class StringStartsWith
{
public static void main(String[] ar)
{
String str1= new String("321... Let's go!!!");
System.out.println("String is " + str1);
boolean boo1 = str1.startsWith("Let's");
System.out.println("Does String "+ str1 + " starts with Let's ? "+ boo1);
boolean boo1 = str1.startsWith("21");
System.out.println("Does String "+ str1 + " starts with 21? "+ boo1);
boolean boo2 = str1.startsWith("321");
System.out.println("Does String "+ str1 + " starts with 321 ? "+ boo2);
boolean boo3 = str1.startsWith("321..");
System.out.println("Does String "+ str1 + " starts with 321.. ? "+ boo3);
}
}
String is 321... Let's go!!!
Does String 321... Let's go!!! starts with Let's ? false
Does String 321... Let's go!!! starts with 21 ? false
Does String 321... Let's go!!! starts with 321 ? true
Does String 321... Let's go!!! starts with 321.. ? true
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement