Java startsWith () method
startsWith () method is used to detect whether the string starts with the specified prefix.
grammar
public boolean startsWith(String prefix, int toffset) 或 public boolean startsWith(String prefix)
parameter
prefix - the prefix.
toffset - the string to start searching.
return value
If the string with the specified prefix beginning, returns true; otherwise false.
Examples
public class Test { public static void main(String args[]) { String Str = new String("www.w3big.com"); System.out.print("返回值 :" ); System.out.println(Str.startsWith("www") ); System.out.print("返回值 :" ); System.out.println(Str.startsWith("w3big") ); System.out.print("返回值 :" ); System.out.println(Str.startsWith("w3big", 4) ); } }
The above program execution results:
返回值 :true 返回值 :false 返回值 :true