0
Can you give me information about indexOf () method please?
String txt = "Please locate where 'locate' occurs!"; System.out.println(txt.indexOf("locate")); it outputs 7. How this happens
2 ответов
+ 1
The indexOf() returns the index of first occurrence of "locate" which begins at index 7.
Use this to return the last occurrence-
System.out.print(txt.lastIndexOf("locate"));
0
Ok, thanks