String 類的常用方法 20170728

2021-08-04 14:28:45 字數 529 閱讀 1130

: 返回指定索引處的char值

compareto  :按字典順序比較兩個字串

contains      :當且僅當此字串包含指定的char值序列時,返回true

endswith    :測試此字串是否以指定的字尾結束

startswith   :測試此字串是否以指定的字首開始

indexof       :返回指定子字串在此字串中第一次出現處的索引

lastindexof :返回指定字元在此字串中最後一次出現處的索引

length         :返回此字串的長度

replace       :返回乙個新的字串,它是通過用 newchar 替換此字串中出現的所有oldchar得到的

startswith   :左包含,右不包含

String 類常用方法

字串 就是由多個字元組成的一串陣列 一旦被複製,就不能被改變 public class stringdemo string s2 new string bys system.out.println s2 s2 system.out.println s2.length s2.length 5 syst...

String類常用方法

方法名稱 型別 方法描述 public string char value 構造 將字元陣列變為string類物件 public string char value,int offset int count 構造 將部分字元陣列變為string類物件 public char charat int i...

String類常用方法

返回字串長度 public int length 返回字串中指定位置的字元 public char charat int index 提取字串 方法說明 public string substring int beginindex 從beginindex位置起,從當前字串中取出剩餘的字元作為乙個新的...