java String的各種方法及操作

來源:互聯網
上載者:User

標籤:字串   大小   boolean   字元   enc   位元組數組   指定位置   位置   value   

No.

方法名稱

功能

字元與字串

01

public String(char[] value)

將字元數組中所有內容變為字串

02

public String(char[] value,int offset,int count)

將字元數組中部分內容變為字串

03

public char charAt(int index)

取得指定索引位置的字元,索引從0開始

04

public char[] toCharArray()

將字串變為字元數組返回

位元組與字串

01

public String(byte[] bytes)

將位元組數組中所有內容變為字串

02

public String(byte[] bytes,int offset,int length)

將位元組數組中部分內容變為字串

03

public byte[] getBytes()

將字串以位元組數組的形式返回

04

public byte[] getBytes(String charsetName) throws UnsupportedEncodingExcepetion

編碼轉換處理

字串比較

01

public boolean equals(String anObject)

區分大小寫比較

02

public boolean equalsIgnoreCase(String anotherString)

不區分大小寫比較

03

public int compareTo(String anotherString)

比較兩個字串的大小關係

字串尋找

01

public boolean contains(String s)

判斷一個子字串是否存在

02

public int indexOf(String str)

從頭開始尋找指定字元的位置,查到了返回位置的開始索引,查不到返回-1

03

public int indexOf(String str,int fromIndex)

從指定位置尋找子字元的位置

04

public int lastIndex(String str)

從後往前尋找子字元的位置

05

public int lastIndex(String str,int fromIndex)

從指定位置由後往前尋找子字元的位置

06

public boolean startsWith(String prefix)

從頭開始判斷是否以指定的字串開頭

07

public boolean startsWith(String prefix,int toffset)

從指定位置開始判斷是否以指定的字串開頭

08

public boolean endsWith(String suffix)

判斷是否以指定的字串結尾

字串替換

01

public String replaceAll(String regex,String replacement)

替換所有內容

02

public String replaceFirst(String regex,String replacement)

替換首個內容

字串拆分

01

public String[] split(String regex)

將字串全部拆分

02

public String[] split(String regex,int limit)

將字串部分拆分,該數組長度就是limit

字串截取

01

public String substring(int beginIndex)

從指定索引截取到結尾

02

public String substring(int beginIndex,int endIndex)

截取部分內容

其他動作

01

public String trim()

去掉字串中的左右空格,保留中間空格

02

public String toUpperCase()

字串轉大寫

03

public String toLowerCase()

字串轉小寫

04

public String interm()

字串入對象池

05

public String concat(String str)

字串串連,等同於”+”

06

public int length()

取得字串長度

07

public boolean inEmpty()

判斷是否為空白(不是null,而是長度為空白)

java String的各種方法及操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.