Hi,
For searching for a particular substring from a starting index of a string and get the starting index of it in JAVA, use the following sample of code.
public class MainClass{ public static void main(String[] arg){ String myStr = "coderzco"; int begIndex= 2; int myIndex= 0; myIndex = str.indexOf("co", begIndex); System.out.println(myIndex); } }
It will print out the starting index of the substring ‘co’ (the second ‘co’), that is 6.
🙂