以下實例中我們通過字符串函數 strOrig.lastIndexOf(Stringname) 來查找子字符串 Stringname 在 strOrig 出現的位置:
也可以從前向后遍歷數據,判斷里面strOrig[i]=="Runoob",i++;
String strOrig = "Hello world ,Hello Runoob";
int lastIndex = strOrig.lastIndexOf("Runoob").;
if(lastIndex == - 1)
{
System.out.println("沒有找到字符串 Runoob"); }
else
{
System.out.println("Runoob 字符串最后出現的位置: "+ lastIndex);
}