此方法从指定的索引开始,返回指定子字符串首次出现在该字符串内的索引。如果没找到,则返回-1。
int indexOf - 语法
int indexOf(String str, int fromIndex)
这是参数的详细信息-
fromIndex - 从中开始搜索的索引。
str - 一个字符串。
int indexOf - 示例
import java.io.*; public class Test { public static void main(String args[]) { String Str=new String("Welcome to Learnfk.com"); String SubStr1=new String("Tutorials" ); System.out.print("Found Index :" ); System.out.println( Str.indexOf( SubStr1, 15 )); } }
这将产生以下输出-
Found Index :-1