Java中String類的字符串的字段包含問題

package changYongLei;

public class ZiDuanBaoHan_String {
  public static void main(String[] args) {
   String s1 = "China people countrys";
//   endsWith(String suffix) 測試此字符串是否以指定的後綴(字符串)結束。-----boolean
   System.out.println(s1.endsWith("trys"));//true
   System.out.println(s1.endsWith("try"));//false

//   startsWith(String prefix)  測試此字符串是否以指定的前綴()字符串開始。-----boolean
   System.out.println(s1.startsWith("China"));//true
   System.out.println(s1.startsWith("china"));//false,注意大小寫

//   startsWith(String prefix, int toffset) 測試此字符串從指定索引開始的子字符串是否以指定前綴(字符串)開始。
   System.out.println(s1.startsWith("ina",2));//true,從索引爲2處開始判斷字符串
   System.out.println(s1.startsWith("ina",1));//false

//   contains(CharSequence s) 當且僅當此字符串包含指定的 char 值序列時,返回 true。----boolean
//   即:判斷此字符串中是否包含指定的字符序列
   System.out.println(s1.contains("people"));//true
   System.out.println(s1.contains("wowoowow"));//false
  }
}

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章