Finding second occurrence of a substring in a string in Java

前端 未结 5 1846
孤城傲影
孤城傲影 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:34

    int first = string.indexOf("is");
    int second = string.indexOf("is", first + 1);
    

    This overload starts looking for the substring from the given index.

提交回复
热议问题