美文网首页
java中String类型里封装了查找子字符串方法

java中String类型里封装了查找子字符串方法

作者: FiveZM | 来源:发表于2018-03-22 20:33 被阅读0次

/**

  • 直接调用String对象的方法,String.indexOf(pattern);返回子字符串第一次在String中出现的索引,如果不存在子字符串则返回-1
  • @author Administrator

*/

public class test {

    public static void main(String[] args) {
        String txt = "ABACADABRAC";
        String pattern = "ABRA";
        int i = txt.indexOf(pattern);
        System.out.println(i);
    }

}

相关文章

网友评论

      本文标题:java中String类型里封装了查找子字符串方法

      本文链接:https://www.haomeiwen.com/subject/hnjzqftx.html