java String 常用方法集合

來源:互聯網
上載者:User

標籤:class   contains   case   ring   ace   輸出   abc   upper   compare   

String a = "abc";
String b = "abc";
a==b ;//返回true,因為a,b指向的是同一個地址


String a = new String("abc");
String b = new String("abc");
a==b;//返回false,因為a,b指向的不是同一個地址
------------------------------------------------------------
a = "abc def";
b ="abc def";
a.charAt(2);//尋找下標為2的字元
a.compareTo("Abc");//和該字串比大小,直到有一個字元不一樣大
a.concat("ghi");//a = a+"ghi";效果一樣
a.endsWith("def");//判斷是否以def結尾
a.startWith("abc");//判斷是否以abc開頭
a.contains("abc");//判斷是否包含abc
a.equals(b);//判斷a和b字串的內容是否相等
a.indexOf("c");//判斷首次出現“c”的位置
a.lastIndexOf("c");//判斷最後一次出現“c”的位置
a.indexOf("c",2);//判斷從下標為2的的字元開始,首次出現“c”的位置
a.length();//a的長度
a.replace(‘c‘,‘a‘);//用“a”替換字串裡的“c”
String[] arr = a.split(" ");//將字串以空格分為數組
a.substring(3);//從下標3開始輸出,直到末尾
a.substring(3,5);//輸出下標3到5的字元
a.toLowerCase();//將字串變為小寫
a.toUpperCase();//將字串變為大寫

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.