//查找字符或字符串 int in = str2.indexOf("d"); System.out.println("ab =" + in); int la = str2.lastIndexOf("d");//课后 System.out.println("d =" + la); String newStr = str2.substring(5); newStr = str2.substring(5,6); System.out.println("substring() =" + newStr); str2 = " ab cdd s "; //去除前后空格 System.out.println("去空格 =" + str2.trim() + "后面"); //查找替换 System.out.println("查找替换空格 =" + str2.replace(" ", "") + "后面"); str2 = "abc,你好,abcd"; System.out.println("查找替换 =" + str2.replace("abc", "李四") + ""); System.out.println("查找替换 =" + str2.replaceFirst("abc", "张三") + ""); str2 = "abcdef"; //判断字符串开始和结束 System.out.println("判断起始1 =" + str2.startsWith("abc")); System.out.println("判断起始2 =" + (str2.indexOf("abc") == 0)); System.out.println("判断结束 =" + str2.endsWith("ef") + " ");