1 /** 2 * java字符串操作 3 * @author wydream 4 * 5 */ 6 7 public class StringTest { 8 9 public static void main(String[] args) { 10 String str="abCdeFg"; 11 12 //1.length():统计字符串长度 13 System.out.println(str.length()); 14 15 //2.indexOf:查找指定字符再字符串中的位置 16 System.out.println(str.indexOf("b")); 17 18 //3.toUpperCase:小写转大写 19 System.out.println(str.toUpperCase()); 20 21 //4.toLowerCase:大写转小写 22 System.out.println(str.toLowerCase()); 23 24 //5.substring:截取字符串 25 System.out.println(str.substring(0,3)); 26 System.out.println(str.substring(3)); 27 28 //6.replaceAll:替换当前字符串中指定的内容 29 str.replaceAll("ab", "xy"); 30 System.out.println(str); 31 32 //7.trim:去掉当前字符串中两端的空格 33 str=" adeg efe efe "; 34 System.out.println(str.trim()); 35 36 //8.+:字符串拼接 37 String str1="I LOVE "; 38 String str2="YOU"; 39 System.out.println(str1+str2); 40 41 //9 将字符串变为整数 42 String str3="123"; 43 int num=Integer.parseInt(str3); 44 System.out.println(num); 45 46 47 } 48 49 }