java經典演算法_036字串常用方法

來源:互聯網
上載者:User
字串1、擷取字串的長度length()2 、判斷字串的首碼或尾碼與已知字串是否相同首碼 startsWith(String s)尾碼 endsWith(String s)3、比較兩個字串equals(String s)4、把字串轉化為相應的數值int 型 Integer.parseInt(字串)long 型 Long.parseLong(字串)float 型 Folat.valueOf(字串).floatValue()double 型 Double.valueOf(字串).doubleValue()4、將數值轉化為字串valueOf(數值)5、字串檢索indexOf(Srting s) 從頭開始檢索indexOf(String s ,int startpoint) 從startpoint 處開始檢索如果沒有檢索到,將返回-16、得到字串的子字串substring(int startpoint) 從startpoint 處開始擷取substring(int start,int end) 從start 到end 中間的字元7、替換字串中的字元,去掉字串前後空格replace(char old,char new) 用new 替換oldtrim()8、分析字串StringTokenizer(String s) 構造一個分析器,使用預設分隔字元(空格,換行,斷行符號,Tab,進紙符)StringTokenizer(String s,String delim) delim是自己定義的分隔字元nextToken() 逐個擷取字串中的語言符號boolean hasMoreTokens() 只要字串還有語言符號將返回true,否則返回falsecountTokens() 得到一共有多少個語言符號

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.