此方法返回指定字符第一次出现的此字符串中的索引,在指定索引处开始搜索,如果未出现该字符,则返回-1。
以下是此方法的语法 -
public int indexOf(int ch, int fromIndex)
这是参数的细节 -
ch - 一个角色。
fromIndex - 从中开始搜索的索引。
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to iowiki.com");
System.out.print("Found Index :" );
System.out.println(Str.indexOf( 'o', 5 ));
}
}
这将产生以下结果 -
Found Index :9