In this example, we have shared Java String lastIndexOf() example. The lastIndexOf() function is java builtin function and it returns the position of the last occurrence of a specified value in a string.
lastIndexOf() Example #1
1 2 3 4 5 6 7 | public class LastIndexOfExample3 { public static void main(String[] args) { String str = "This is last index of example"; int index = str.lastIndexOf("of"); System.out.println(index); } } |
lastIndexOf() Example #2
1 2 3 4 5 | public static void main(String args[]){ String s1="this is index of example";//there are 2 's' characters in this sentence int index1=s1.lastIndexOf('s');//returns last index of 's' char value System.out.println(index1);//6 }} |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.