public class Test{
public static void main(String[] args){
//1、字符串转换为char
char c = "胶带".charAt(1);
System.out.println(c); //带
//2、字符串之间比较大小,左小右大负数,左大右小正数
int retValue = "abc".compareTo("abd");
System.out.println(retValue); //-1
//3、判断前面的字符串中是否包含后面的子字符串
boolean b = "abc".contains("a");
System.out.println(b); //true
//4、判断当前字符串是否以某个字符串结尾
boolean c2 = "abc".endsWith("c");
System.out.println(c2); //true
//5、判断两个字符串是否相等,并且忽略大小写
boolean d = "Abc".equalsIgnoreCase("aBc");
System.out.println(d); //true
//6、将字符串转换成字节数组
byte[] bytes = "abc".getBytes();
for(byte b2 : bytes){
System.out.println(b2); //97 98 99
}
//7、判断某个子字符串在当前字符串中第一次出现处的索引
int retValue2 = "abcb".indexOf("b");
System.out.println(retValue2); //1
//8、判断某个字符串是否为空
boolean e = "".isEmpty();
System.out.println(e); //true
//9、判断字符串长度
int retValue3 = "abc".length();
System.out.println(retValue3); //3
//10、判断某个字符串在当前字符串中最后一次出现的索引
int retValue4 = "abcb".lastIndexOf("b");
System.out.println(retValue4); //3
//11、将字符串中的某个字符换成别的字符
String s = "aaabbbccc".replace("a","b");
System.out.println(s); //bbbbbbccc
//12、拆分字符串
String[] strs = "a-b-c".split("-");
for(String s2 : strs){
System.out.println(s2); //a b c
}
//13、判断某个字符串是否以某个字符串开始
boolean f = "abc".startsWith("a"); //true
System.out.println(f);
//14、截取字符串*开始下标,结束下标
String s2 = "abcd".substring(1,3); //bc
System.out.println(s2);
//15、将字符串转换成char数组
char[] chars = "abc".toCharArray();
for(char c3 : chars){
System.out.println(c3); //a b c
}
//16、转换成小写
String s3 = "ABC".toLowerCase();
System.out.println(s3); //abc
//17、转换成大写
String s4 = "abc".toUpperCase(); //ABC
System.out.println(s4);
//18、去除字符串前后空白,不去中间空白
String s5 = " a b c ".trim(); //a b c
System.out.println(s5);
//19、将非字符串转换为字符串
String s6 = String.valueOf(123);
System.out.println(s6); //123
}
}