rustock rustock - 3 months ago 20
Java Question

How to return the next indexOf after a previous?

For example:

str = "(a+b)*(c+d)*(e+f)"
str.indexOf("(") = 0
str.lastIndexOf("(") = 12


How to get the index in second bracket?
(c+d) <- this

Answer

Try this :

 String word = "(a+b)*(c+d)*(e+f)";
 String c = "(";
  for (int index = word.indexOf(c);index >= 0; index = word.indexOf(c, index + 1)) {
       System.out.println(index);//////here you will get all the index of  "("
    }