startsWith和endsWith判断字符串是否是以给定的内容开始或结束的

 1 /**
 2  * boolean startsWith(String str)
 3  * boolean endsWith(String str)
 4  * 判断字符串是否是以给定的内容开始或结束的
 5  *
 6  */
 7 public class StartsWithDemo {
 8     public static void main(String[] args) {
 9         String line = "www.baidu.com";
10         boolean starts = line.startsWith("www.");
11         System.out.println("start:"+starts);
12 
13         boolean ends = line.endsWith(".com");
14         System.out.println("end:"+ends);
15     }
16 }

 

posted @ 2021-09-22 20:39  牵你不解释  阅读(80)  评论(0)    收藏  举报