String类中常用的方法(二)

  1. 判断某字符串是否以指定字符结束
  2. 判断某字符串是否以指定字符开始
  3. 判断某字符串内是否存在指定字符串
  4. 判断某字符串是否存在指定字符中,返回该字符出现的位置
  5. 指定从某个位置开始找,找到了就返回从起始位置开始数的索引
public class StringMethod02 {
    @Test
    public  void test(){
        String s="HelloWorld";

        System.out.println(s.endsWith("d"));//   是否以指定字符串结束  返回值为true or false

        System.out.println(s.startsWith("H"));// 是否以指定字符串开始  返回值为true or false

        System.out.println(s.startsWith("e",1)); // 判断指定位置开始的字符串是否为所指定的字符

        String  s1="he";
        System.out.println(s.contains(s1)); //判断某字符串内是否存在指定字符串 返回值为true or false

        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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值