String
1 /** 2 * 无参数构造 3 * */ 4 String s = new String(); 5 6 /** 7 * 字符数组构造 8 * */ 9 10 char chars[] = {'A', 'B', 'C'}; 11 String s1 = new String(chars); 12 System.out.println(s1); 13 14 /** 15 * 字节数字构造 16 * */ 17 byte bytes[] = {92, 20, 32}; 18 String s2 = new String(bytes); 19 System.out.println(s2); 20 21 /**字符串判断方法 22 * */ 23 24 String str1 = "hello"; 25 String str2 = "hello"; 26 String str3 = "hello"; 27 System.out.println(str1.equals(str2)); 28 System.out.println(str2.equals(str3)); 29 System.out.println(str1.equals(str3)); 30 31 /**判断字符串相等忽略大小写 32 * */ 33 34 String str4 = "Jack"; 35 String str5 = "jack"; 36 System.out.println(str4.equalsIgnoreCase(str5)); 37 38 /** 判断地址值 39 * */ 40 41 String str6 = str1; 42 char chars2[] = {'h', 'e', 'l', 'l', '0'}; 43 String str7 = new String(chars2); 44 45 System.out.println(str1 == str6); 46 System.out.println(str7 == str6); 47 48 /** 49 * 获取方法 50 * */ 51 System.out.println(str1.length()); 52 System.out.println(str1.concat(str2)); 53 System.out.println(str1.charAt(0)); 54 System.out.println(str1.indexOf('h')); 55 System.out.println(str1.substring(1, 3)); 56 System.out.println(str1.substring(0, str1.length())); 57 58 /** 59 * 转化方法 60 * */ 61 62 char[] chars1 = str1.toCharArray(); 63 for (int i = 0; i < chars1.length ; i++) { 64 System.out.println(chars1[i]); 65 } 66 67 byte[] bytes1 = str1.getBytes(); 68 for (int i = 0; i <bytes.length ; i++) { 69 System.out.println(bytes1[i]); 70 } 71 72 System.out.println(str1.replace("h", "*")); 73 74 /** 75 * 分割方法 76 * */ 77 String str008 = "hello world"; 78 String[] split = str008.split(""); 79 for (int i = 0; i < split.length ; i++) { 80 System.out.println(split[i]); 81 }