String can be checked if prefix start with some string characters or string literal with the help of startsWith() method in java. startsWith() method returns a value in boolean, if string literal is found in starting of string index, it will return true, otherwise it will return false. Use of String startsWith() in java is shown below.
Example of String startsWith() in java, JSP
public class StringStartsWithExample { public static void main(String[] args) { String string = "This Java String"; boolean check1=string.startsWith("This"); boolean check2=string.startsWith("Java"); System.out.println("check1 :"+check1); System.out.println("check2 :"+check2); // example 2 boolean check3=string.startsWith("Java", 5); System.out.println("check3 :"+check3); } }
Output
check1 :true
check2 :false
check3 :true
Tags: String




Link to Us