物件導向15.3String類-常見功能-轉換

來源:互聯網
上載者:User

標籤:rgs   ace   ati   for   length   2.7   out   意思   array   

public static void main(String[] args) {
//2.1
//String s="張三,李四,王五";
//String [] arr=s.split(",");//。s.split(",")這個意思是拿逗號來切(這個括弧裡面放的是規則)
//for (int i = 0; i < arr.length; i++) {
//System.out.println(arr[i]);
//}
//2.2
//String s="張三,李四,王五";
//char [] ch=s.toCharArray();
//for (int i = 0; i < ch.length; i++) {
//System.out.println(ch[i]);
//}
//2.3
//String s="adfgcv";
//byte [] by=s.getBytes();
//for (int i = 0; i < by.length; i++) {
//System.out.println(by[i]);
//}
//2.4
//System.err.println("qweqwerqsdzlkfgjalsdkfjasid".toUpperCase());//字元都轉換為大寫
//System.out.println("ASDKJFHKAH".toLowerCase());//字元都轉換為小寫
//2.5
System.out.println("java".replace(‘j‘,‘k‘));//kava把原本的j替換成了k
System.out.println("java".replace(‘q‘,‘k‘));//java,在java字串裡面沒有q,所以沒有替換成功,沒有替換成功就還是原來的老的
String s1="java";
String s2=s1.replace(‘d‘, ‘c‘);
System.out.println(s1==s2);//true
//2.6
System.out.println("-------- "+" ab c ".trim()+"----");//.trim()去除字串兩端的空格(用途:在開發的時候有的一些使用者,在輸入帳號密碼的時候,
//不小心輸入空格,有沒有空格是不一樣的,所以我們擷取資訊的時候,要去掉資訊兩邊的空格)
//2.7
System.out.println("abc".concat("ddd"));
System.out.println("abc"+"ddd");
}

物件導向15.3String類-常見功能-轉換

聯繫我們

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