- 判断某字符串是否以指定字符结束
- 判断某字符串是否以指定字符开始
- 判断某字符串内是否存在指定字符串
- 判断某字符串是否存在指定字符中,返回该字符出现的位置
- 指定从某个位置开始找,找到了就返回从起始位置开始数的索引
public class StringMethod02 {
@Test
public void test(){
String s="HelloWorld";
System.out.println(s.endsWith("d"));
System.out.println(s.startsWith("H"));
System.out.println(s.startsWith("e",1));
String s1="he";
System.out.println(s.contains(s1));
System.out.println(s.indexOf("s"));
System.out.println(s.indexOf("o",4));
System.out.println(s);
String s2="12155";
System.out.println(s2.indexOf("5"));
System.out.println(s2.indexOf("5",2));
}
}
输出结果
rue
true
true
false
-1
4
HelloWorld
3
3