Finding second occurrence of a substring in a string in Java

前端 未结 5 1849
孤城傲影
孤城傲影 2020-12-01 06:16

We are given a string, say, \"itiswhatitis\" and a substring, say, \"is\". I need to find the index of \'i\' when the string \"i

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 06:49

    Use overloaded version of indexOf(), which takes the starting index (fromIndex) as 2nd parameter:

    str.indexOf("is", str.indexOf("is") + 1);
    

提交回复
热议问题