Here is a Java Program to search the last position of a substring
Output of Above Java Program
Last occurrence of Hello is at index 13
class SearchlastString { public static void main(String[] args) { String strOrig = "Hello world ,Hello Reader"; int lastIndex = strOrig.lastIndexOf("Hello"); if(lastIndex == - 1){ System.out.println("Hello not found"); }else{ System.out.println("Last occurrence of Hello is at index "+ lastIndex); } } }
Output of Above Java Program
Last occurrence of Hello is at index 13