System.out.println(str9.substring(4, str9.length()));//dabc String str11 = \
System.out.println(str11.substring(4, str11.length()));//.jpg
// concat:连接字符串
System.out.println(str9.concat(str11));//abccdabctest.jpg
System.out.println(str9 + str11);//abccdabctest.jpg // contains:包含某个字符串
System.out.println(str11.contains(\ // replace:字符串替换
System.out.println(str11.replace(\\
// split:分割字符串 String str12 = \ //String[] strs = str12.split(\ String[] strs = str12.split(\ System.out.println(strs.length);
for(int i = 0; i < strs.length; i++){
System.out.println(\+ i + \+ strs[i]);//str[0]=aa }
// toLowerCase():转换成小写 // toUpperCase():转换成大写
System.out.println(str12.toLowerCase());//test.jpg
System.out.println(str12.toUpperCase());//TEST.JPG // trim():去前后空格 String str13 = \
System.out.println(str13.length());//5 String str14 = str13.trim(); System.out.println(str14);
System.out.println(str14.length());//3
// regionMatches:测试两个字符串区域是否相等。
String str15 = \ String str16 = \
boolean flag = str15.regionMatches(0, str16, 0, str16.length());
System.out.println(\
flag = str15.regionMatches(1, str16, 1, str16.length() - 1);
System.out.println(\ flag
=
str15.regionMatches(3,
str16,
3,
6);//str16=\
System.out.println(\
// 将“数字”组成的字符串转换为基本数据类型 int a = Integer.parseInt(\ System.out.println(a);
float f = Float.parseFloat(\ System.out.println(f);
double d = Double.parseDouble(\ System.out.println(d);
// 将基本数据类型转换为字符串 String s1 = String.valueOf(a); String s2 = String.valueOf(f); String s3 = String.valueOf(d);
/*// equals() // ==
A a1 = new A();
A a2 = new A();
System.out.println(a1.equals(a2));//false System.out.println(a1 == a2);//false*/ } }
public static void main(String[] args) { // 字符串与字节数组相互转化 String s1 = \欢迎来abc到网星!\ // 将字符串转换成字节数组 byte [] bytes = s1.getBytes(); // 将字节数组转换成字符串 String s2 = new String(bytes); System.out.println(s2);
System.out.println(\ try {
// 将字符串转换成字节数组
bytes = s1.getBytes(\ISO-8859-1 UTF-8 GBK
// 将字节数组转换成字符串