Java String lastIndexOf(String str)
方法返回子字符串str
在此对象表示的字符序列中最后一次出现的索引,该索引小于或等于fromIndex
,如果该子字符串在fromIndex
之前未出现,则返回-1
。
语法
以下是此方法的语法 -
public int lastIndexOf(String str)
参数
str
- 要查找的子字符串。
返回值
- 此方法返回索引值。
示例
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to xuhuhu.com");
String SubStr1 = new String("Yii");
System.out.print("Found Last Index :");
System.out.println(Str.lastIndexOf(SubStr1));
}
}
执行上面查询语句,得到以下结果:
Found Last Index :11
上一篇:
java中方法重载和方法重写的区别
下一篇:无