class JavaTest4_String {
public static void main(String[] args) {
String str1 = "IOS,ANDROID,BB,PALNM,WP,SYBIAN";
String str2 = new String("Str2");
char[] arr = {'S','t','r','2'};
String str3 = new String(arr);
String str4 = " Jue ";
//长度
System.out.println("长度");
System.out.println(str1+"\t的长度为:"+str1.length());
System.out.println(str2+"\t的长度为:"+str2.length());
System.out.println(str3+"\t的长度为:"+str3.length());
System.out.println(str4+"\t的长度为:"+str4.length());
System.out.println();
//拆分
System.out.println("拆分");
String[] strarr = str1.split(",");
for(String s : strarr){
System.out.print(s+"\t");
}
System.out.println();
System.out.println();
//查找
System.out.println("查找");
System.out.println(str1.indexOf("BB"));
System.out.println(str1.indexOf("S"));
System.out.println(str1.indexOf("ZZ"));
System.out.println();
//替换
System.out.println("替换");
System.out.println(str1.replaceAll("BB","CC"));
System.out.println(str1.replaceAll(",","|"));
System.out.println(str1.replaceFirst(",","|"));
System.out.println();
//返回字符串的副本,忽略前导空白和尾部空白
System.out.println("返回字符串的副本,忽略前导空白和尾部空白");
System.out.println(str4);
System.out.println(str4.trim());
System.out.println();
//相等
System.out.println("判断字符串相等");
System.out.println(str2.equals(str3));
System.out.println(str2==str3);
System.out.println();
//换大小写
System.out.println(str1.toLowerCase());
System.out.println(str2.toUpperCase());
System.out.println();
System.out.println();
}
}
/*
---------- 运行 ----------
长度
IOS,ANDROID,BB,PALNM,WP,SYBIAN的长度为:30
Str2的长度为:4
Str2的长度为:4
Jue 的长度为:22
拆分
IOSANDROIDBBPALNMWPSYBIAN
查找
12
2
-1
替换
IOS,ANDROID,CC,PALNM,WP,SYBIAN
IOS|ANDROID|BB|PALNM|WP|SYBIAN
IOS|ANDROID,BB,PALNM,WP,SYBIAN
返回字符串的副本,忽略前导空白和尾部空白
Jue
Jue
判断字符串相等
true
false
ios,android,bb,palnm,wp,sybian
STR2
输出完成 (耗时 0 秒) - 正常终止
*/