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中方法重載和方法重寫的區別
下一篇:無