当前位置: 首页 > 文档资料 > 学习 Java 编程 >

int indexOf(String str, int fromIndex)

优质
小牛编辑
121浏览
2023-12-01

描述 (Description)

此方法返回指定子字符串第一次出现的字符串中的索引,从指定的索引开始。 如果没有发生,则返回-1。

语法 (Syntax)

以下是此方法的语法 -

int indexOf(String str, int fromIndex)

参数 (Parameters)

这是参数的细节 -

  • fromIndex - 从中开始搜索的索引。

  • str - 一个字符串。

返回值 (Return Value)

  • See the description.

例子 (Example)

import java.io.*;
public class Test {
   public static void main(String args[]) {
      String Str = new String("Welcome to iowiki.com");
      String SubStr1 = new String("Tutorials" );
      System.out.print("Found Index :" );
      System.out.println( Str.indexOf( SubStr1, 15 ));
   }
}

这将产生以下结果 -

输出 (Output)

Found Index :-1