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);



It will print out the starting index of the substring ‘co’ (the second ‘co’), that is 6.



Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.