(11)boolean contains(xx):是否包含xx
@Test
public void test11() {
String s1 = new String("今天是2021年10月4日,国庆假期的第四天");
boolean b1 = s1.contains("国庆假期");//true
System.out.println(b1);
boolean b2 = s1.contains("第五天");
System.out.println(b2);//false
}
(12)int indexOf(xx):从前往后找当前字符串中xx,即如果有返回第一次出现的下标,要是没有返回-1
@Test
public void test12() {
String s1 = new String("今天是2021年10月4日,国庆假期的第四天");
int i1 = s1.indexOf("国庆假期");
System.out.println(i1);//14
int i2 = s1.indexOf("天");
System.out.println(i2);//1
int i3 = s1.indexOf("第五天");
System.out.println(i3);//-1
}
(13)int lastIndexOf(xx):从后往前找当前字符串中xx,即如果有返回最后一次出现的下标,要是没有返回-1
@Test
public void test13() {
String s1 = new String("今天是2021年10月4日,国庆假期的第四天");
int i1 = s1.lastIndexOf("国庆假期");
System.out.println(i1);//14
int i2 = s1.lastIndexOf("天");
System.out.println(i2);//21
int i3 = s1.lastIndexOf("第五天");
System.out.println(i3);//-1
}
(14)String substring(int beginIndex) :返回一个新的字符串,它是此字符串的从beginIndex开始截取到最后的一个子字符串。
@Test
public void test14() {
String s1 = new String("今天是2021年10月4日,国庆假期的第四天");
String substring = s1.substring(14);
System.out.println(substring);//国庆假期的第四天
}
15)String substring(int beginIndex, int endIndex) :返回一个新字符串,它是此字符串从beginIndex开始截取到endIndex(不包含)的一个子字符串。
@Test
public void test15() {
String s1 = new String("今天是2021年10月4日,国庆假期的第四天");
String substring = s1.substring(14,18);
System.out.println(substring);//国庆假期
}
(16)char charAt(index):返回[index]位置的字符
@Test
public void test16() {
String s1 = new String("helloworld");
char c = s1.charAt(0);
System.out.println(c);//h
}
(17)char[] toCharArray(): 将此字符串转换为一个新的字符数组返回
@Test
public void test17() {
String s1 = new String("helloworld");
char[] chars = s1.toCharArray();
for (int i = 0; i < chars.length; i++) {
System.out.print(chars[i] + " ");//h e l l o w o r l d
}
}
(18)String(char[] value):返回指定数组中表示该字符序列的 String。
@Test
public void test18() {
char[] chars = {'h','e','l','l','o'};
String s = new String(chars);
System.out.println(s);//hello
}
(19)String(char[] value, int offset, int count):返回指定数组中表示该字符序列的 String。
@Test
public void test19() {
char[] chars = {'h','e','l','l','o'};
String s = new String(chars,0,2);
System.out.println(s);//he
}
(20)static String copyValueOf(char[] data): 返回指定数组中表示该字符序列的 String
@Test
public void test20() {
char[] chars = {'h','e','l','l','o'};
String s = String.copyValueOf(chars);
System.out.println(s);//hello
}
(21)static String copyValueOf(char[] data, int offset, int count):返回指定数组中表示该字符序列的 String
@Test
public void test21() {
char[] chars = {'h','e','l','l','o'};
String s = String.copyValueOf(chars,0,2);
System.out.println(s);//he
}
(22)static String valueOf(char[] data) :返回指定数组中表示该字符序列的 String
@Test
public void test22() {
char[] chars = {'h','e','l','l','o'};
String s = String.valueOf(chars);
System.out.println(s);//hello
}
(23)static String valueOf(char[] data, int offset, int count) : 返回指定数组中表示该字符序列的 String
@Test
public void test23() {
char[] chars = {'h','e','l','l','o'};
String s = String.valueOf(chars,0,2);
System.out.println(s);//he
}



