Java基礎_String

來源:互聯網
上載者:User

標籤:[]   i++   區分大小寫   indexof   nbsp   substring   start   case   編碼   

1. equals  , 比較字串內容,區分大小寫

String s1 = "abc";String s2 = "aBc";System.out.println(s1.equals(s2)); --->false

 2.equalsIgnoreCase ,比較字串內容,不區分大小寫

String s1 = "abc";String s2 = "aBc";System.out.println(s1.equalsIgnoreCase(s2)); --->true

 3.contains,字串中是否包含且全部包含,區分大小寫

String s1 = "ABCDEF";String s2 = "F";String s3 = "f";System.out.println(s1.contains(s2)); --- >trueSystem.out.println(s1.contains(s3)); --- >false

 4.startsWith,判斷字串開始值,區分大小寫

String s1 = "ABCDEF";System.out.println(s1.startsWith("A")); --->trueSystem.out.println(s1.startsWith("B", 1)); --->trueSystem.out.println(s1.endsWith("f")); --->false

 5.isEmpty ,判斷是否為空白

String s1 = "ABCDEF";System.out.println(s1.isEmpty()); --- >false

 

6.int length()

7.char charAt(int index)  從字串中返回 所在位置的字元

8.int indexof(int ch)  返回第一次出現的索引

9.int indexOf(String)

10.String subString(int start ,  (int end) )   截取字串

 

11.getBytes 編碼,把字串轉換為字元數組

String s1 = "ABCDEF";byte[] arr =s1.getBytes();for(int i=0;i<s1.length();i++){System.out.println(arr[i]);}

 把字元數組轉化為字串

String s2= new String(arr);System.out.println(s2);

 

12.string replace(char old ,char new )

13.string replace(String old ,String new)

14.trim()

 

...不一一列舉了

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.