startsWith() 方法用于检测字符串是否以指定的前缀开始。

 1 public class Test {    
 2  public static void main(String args[]) {        
 4      String Str = new String("www.runoob.com");         
 6      System.out.print("返回值 :" );        
 8       System.out.println(Str.startsWith("www") );         
10       System.out.print("返回值 :" );       
12       System.out.println(Str.startsWith("runoob") );         
14       System.out.print("返回值 :" );       
16       System.out.println(Str.startsWith("runoob", 4) ); 
19 }}
20 
21 以上程序执行结果为:
22 
23 返回值 :true
24 返回值 :false
25 返回值 :true
原文地址:https://www.cnblogs.com/zhanghongpan/p/12627757.html