1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* String startsWith Example This example shows how to check if a particular string is starting with a specified word. */ public class StringStartsWithExample { public static void main(String[] args) { //declare the original String String strOrig = "Hello World"; /* check whether String starts with Hello or not. Use startsWith method of the String class to check the same. startsWith() method returns true if a string is starting with a given word otherwise it returns false */ if(strOrig.startsWith("Hello")){ System.out.println("String starts with Hello"); }else{ System.out.println("String does not start with Hello"); } } } /* Output of the program would be : String starts with Hello */ |
What will be if “strOrig” is null or empty?