使用indexOf方法在source中查找target的第一次出现的索引位置。 intindex=source.indexOf(target); 1. 如果index的值大于等于 0,则表示找到了匹配的字符串。此时,我们将计数器count加一,并继续在source中查找target的下一次出现。 while(index>=0){count++;index=source.indexOf(target,index+1);} 1. 2. 3. ...
String str="1qaz2wsxzaq12wsx"; System.out.println("查找:"); //查找指定字符第一次出现的位置,参数为字符的ascii码 a-97 int test1=str.indexOf(97); //查找指定字符串第一次出现的位置 int test2=str.indexOf("12"); //如果要查找的不存在,indexOf()返回-1 int test3=str.indexOf("qwer",0...