Java String lastIndexOf(String str, int fromIndex)
方法返回指定子字串此對象表示的字元序列中最後一次出現的索引,該索引小於或等於fromIndex
,如果子字元在fromIndex
之前未找到,則返回-1
。
語法
以下是此方法的語法 -
public int lastIndexOf(String str, int fromIndex)
參數
fromIndex
- 開始搜索的索引。
返回值
- 此方法返回索引值。
示例
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, 10 ));
}
}
執行上面查詢語句,得到以下結果:
Found Last Index : -1
上一篇:
java中方法重載和方法重寫的區別
下一篇:無