This example shows how to determine the last position of a substring inside a string with the help of strOrig.lastIndexOf(Stringname) method.
Code snippet
Code snippet
public class SearchLastString {
public static void main(String args[]){
String str1 = "Welcome to sirsuspect.blogspot.com";
int lastIndex = str.lastIndexOf("Welcome");
if(lastIndex == - 1){
System.out.println("Welcome not found");
}else{
System.out.println("Last occurrence of Welcome is at index" + lastIndex);
}
}
}
|
Output:
The above code sample will produce the following result.
Last occurrence of Welcome is at index 13
|
Source code: