JAVA字串String類的常用方法

2021-09-02 01:47:38 字數 1383 閱讀 2603

string類的構造方法

string

(char a)

string

(char a[

], int offset, int length)

string

(char[

] value)

字串查詢

indexof()

lastindexof()

**獲取指定索引位置的字元**

charat

(int index)

獲取子字串

substring

(int beginindex)

substring

(int beginindex, int endindex)

去除空格

trim

()

字串的替換

replace

(char olchar, char newchar)

判斷字串的開始與結尾

startswith

(string prefix)

endswith

(string suffix)

判斷字串是否相等

equals

(string other)

equalsignorecase

(string other)

按字典順序比較兩個字串

compareto

(string other)

字母大小寫的轉換

tolowercase()

touppercase

()

字串分割

split

(string singn)

split

(string singn, int limit)

格式化字串

format

(string format, object…args)

format

(local l, string format, object…args)

Java 字串常用操作(String類)

string提供了兩種查詢字串的方法,即indexof與lastindexof方法。1 indexof string s 該方法用於返回引數字串s在指定字串中首次出現的索引位置,當呼叫字串的indexof 方法時,會從當前字串的開始位置搜尋s的位置 如果沒有檢索到字串s,該方法返回 1 string...

Java 字串常用操作(String類)

string提供了兩種查詢字串的方法,即indexof與lastindexof方法。1 indexof string s 該方法用於返回引數字串s在指定字串中首次出現的索引位置,當呼叫字串的indexof 方法時,會從當前字串的開始位置搜尋s的位置 如果沒有檢索到字串s,該方法返回 1 1 stri...

Java 字串常用操作(String類)

字串查詢 indexof string s 該方法用於返回引數字串s在指定字串中首次出現的索引位置,當呼叫字串的indexof 方法時,會從當前字串的開始位置搜尋s的位置 如果沒有檢索到字串s,該方法返回 1 string str we are students int size str.index...