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

 

posted @ 2020-04-03 17:27  LuckyKun的羊肉  阅读(562)  评论(0编辑  收藏  举报