Occurrences of substring in a string

后端 未结 24 1896
眼角桃花
眼角桃花 2020-11-22 03:35

Why is the following algorithm not halting for me? (str is the string I am searching in, findStr is the string I am trying to find)

String str = \"helloslkhe         


        
24条回答
  •  旧时难觅i
    2020-11-22 03:58

    public int indexOf(int ch,
                       int fromIndex)
    

    Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

    So your lastindex value is always 0 and it always finds hello in the string.

提交回复
热议问题