Home >Java >javaTutorial >Java Example - Find the last occurrence of a string
In the following example, we use the string function strOrig.lastIndexOf(Stringname) to find the position where the substring Stringname appears in strOrig:
The example 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); } }}
Above The output result of the code example is:
Last occurrence of Hello is at index 13
The above is the Java example - find the content of the last occurrence of a string, please pay attention to more related content PHP Chinese website (www.php.cn)!