无涯教程-Java - int lastIndexOf(String str, int fromIndex)函数

85 阅读1分钟

此方法返回最后一次出现的指定子字符串在此字符串内的索引,从指定索引(fromIndex)开始向后搜索。

int lastIndexOf - 语法

public int lastIndexOf(String str, int fromIndex)

这是参数的详细信息-

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

  • str               -  一个字符串。

int lastIndexOf - 返回值

  • 此方法返回索引位置。

int lastIndexOf - 示例

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str=new String("Welcome to Learnfk.com");
      String SubStr1=new String("Learnfk" );
      System.out.print("Found Last Index :" );
      System.out.println( Str.lastIndexOf( SubStr1, 15 ));
   }
}

这将产生以下输出-

Found Last Index :11

参考链接

www.learnfk.com/java/java-s…