標籤:[] 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