Java indexOf method for multiple matches in String

前端 未结 6 1429
走了就别回头了
走了就别回头了 2020-11-29 06:24

I had a question about the indexOf method. I want to find multiple cases of \"X\" in a string.

Suppose my string is \"x is x is x is x\", I want to find x in all of

6条回答
  •  天涯浪人
    2020-11-29 07:01

    You can specify the start index with indexOf. So, in your loop you store the last position of 'x', then search again using that index + 1.

提交回复
热议问题