public static void main(String[] args) {
String a="defrag";
String b="defrag";
String c="Defrag";
String d=" D efra ge ";
//获取字符串的长度
System.out.println("1."+a.length());
//获取指定字符在对象中出现的第一次索引,如果没有返回-1
System.out.println("2."+a.indexOf("d"));
//获取指定索引处的字符
System.out.println("3."+a.charAt(1));
//从输入的索引位置开始截取字符串
System.out.println("4."+a.substring(4));
//从1号索引位置到4号索引位置,包括1号索引但不包括4号索引
System.out.println("5."+a.substring(1,4));
//比较字符串的内容是否相同
System.out.println("6."+a.equals(c));
//比较字符串的内容是否相同忽略大小写
System.out.println("7."+a.equalsIgnoreCase(c));
//判断字符串对象是否以指定的字符开头(区分大小写)
System.out.println("8."+a.startsWith("d"));
//判断字符对象是否以指定的字符开头(区分大小写)
System.out.println("9."+a.startsWith("f", 2));
//判断字符串对象是否以指定的字符结尾
System.out.println("10."+a.endsWith("f"));
//判断指定字符串是否为空
System.out.println("11."+a.isEmpty());
//比较字符串的大小,前者大返回整数,后者大返回负数,相等返回0.
System.out.println("12."+a.compareTo(c));
//把字符串转换为字符数组
System.out.println("13."+a.toCharArray());
//把字符串转换为小写字符串
System.out.println("14."+c.toLowerCase());
//把字符串转换为大写字符串
System.out.println("15."+a.toUpperCase());
//去除字符串两端的空格
System.out.println("16."+d.trim());
//去除字符串种指定的字符,然后返回结果是个数组,需要遍历这个数组才能打印出来
for (String s : b.split("f|a")) {
System.out.print(s);
}
//截取字符串中指定位置的字符组成一个新的字符串,包括头部不包括尾部
System.out.println();
System.out.println("18."+a.subSequence(2,4));
//将指定字符替换成另一个指定的字符
System.out.println("19."+a.replace("e", "b"));
//用新的内容替换全部旧内容
System.out.println("20."+a.replaceAll("efr","bbb"));
//6)replaceFirst(String regex,String replacement):替换首个满足条件的内容
System.out.println("21."+d.replaceFirst("e","aa"));
//7)lastIndexOf(String str):返回指定字符出现的最后一次的下标
System.out.println("22."+d.lastIndexOf("e"));
//8)contains(CharSequence s):查看字符串中是都含有指定字符
System.out.println("23."+a.contains("e"));
//9)concat(String str):在原有的字符串的基础上加上指定字符串
System.out.println("24."+a.concat("aaa"));
}