InterviewSolution
Saved Bookmarks
| 1. |
Check if a string begins with a specific substring |
|
Answer» The startsWith() METHOD is used to check WHETHER a string begins with a specific string or not. Here, we are checking whether the given string begins with the substring “one”: public class Example { public STATIC void main(String[] ARGS) { String s = "OneAndOnly"; if(s.startsWith("one")) { System.out.println("Begins with the specified word!"); } ELSE { System.out.println("Does not begin with the specified word!"); } } }The output: Begins with the specified word! |
|