How to get index of substring within a String using indexOf() in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            String s = "java c++ c#";

            int i = s.indexOf("c++");
            System.out.println(i);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
5
  
 */

 



answered Nov 21, 2016 by avibootz
...