import java.util.Locale;
public class Demo2 {
public static void main(String[] args) {
//String常用API
String str1="Hello";
System.out.println(str1.charAt(0));//返回 char指定索引处的值
String str2="Hello";
String str3="666";
System.out.println(str2.concat(str3));//将指定的字符串连接到该字符串的末尾
String str4="666你好888";
System.out.println(str4.contains("你好"));//包含子串
String str5="Hello";
System.out.println(str5.startsWith("H"));//以xx开头
System.out.println(str5.startsWith("6"));
System.out.println(str5.endsWith("o"));//以xx结尾
System.out.println(str5.endsWith("6"));
String str6="Hello";
String str7="Hello";
String str8="Hello1";
System.out.println(str6.equals(str7));//判断字符串是否相等
System.out.println(str6.equals(str8));
String str9="H";
String str10="e";
String str11=String.join("/",str9,str10);//join方法
System.out.println(str11);
String str12="hello world";
//hello world
//012345678910
System.out.println(str12.indexOf("l"));//返回第一次出现的索引值
System.out.println(str12.lastIndexOf("l"));//返回最后一次出现的索引值
String str13="";
String str14="Hello";
System.out.println(str13.isEmpty());//判断是否为空
System.out.println(str14.isEmpty());
String str15="Hello";
System.out.println(str15.length());//返回字符串长度
String str16="(abc(ac(bbb)";
System.out.println(str16.replace("(","{"));//replace
System.out.println(str16.replaceAll("\\(","{"));//replaceAll要用到正则表达式
System.out.println(str16.replaceFirst("\\(","{"));//replaceFirst要用到正则表达式
String str17="a_b_c_d_e";
String[] s=str17.split("_");//字符串分割
for (int i = 0; i < s.length; i++) {
System.out.print(s[i]);
}
String str18="abcdef";
System.out.println(str18.substring(1));//字符串分割
System.out.println(str18.substring(0,2));
System.out.println(str18.substring(1,str18.indexOf("e")));//到e之前
String str19="abc";
System.out.println(str19.toUpperCase(Locale.ROOT));//转换大小写
String str20="ABC";
System.out.println(str20.toLowerCase(Locale.ROOT));
}
}
运行结果