Java Examples - Find the last occurrence of the string
The following examples we string functions strOrig.lastIndexOf (Stringname) to locate the position of a substring in strOrig Stringname appear:
Examples of code is as follows:
//SearchlastString.java 文件 public 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); } } }
The output is the above code examples:
Last occurrence of Hello is at index 13