Java indexOf method for multiple matches in String

前端 未结 6 1428
走了就别回头了
走了就别回头了 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:04

    String name = "alameer kaiser aziz";
    String found = "a";
    int num = name.indexOf(found);
    while (num >=0) {
        System.out.println(num);
        num = name.indexOf(found,num+1);
    }
    

提交回复
热议问题