String 类的indexof()方法相关

来源:互联网 发布:gal翻译软件 编辑:程序博客网 时间:2024/05/29 13:15

public class Test {  

   publicstatic void main(String[] args) {  

        String s= "xXccxxxXX";        

      // 从头开始查找是否存在指定的字符,索引从0开始//结果如下   

       System.out.println(s.indexOf("c"));//

       // 从第四个字符位置开始往后继续查找,包含当前位置 

       System.out.println(s.indexOf("c",3)); //

       //若指定字符串中没有该字符则系统返回-1 

       System.out.println(s.indexOf("y"));//-1 

       System.out.println(s.lastIndexOf("x"));//

   } 

原创粉丝点击