Java String.indexOf and empty Strings

后端 未结 5 849
借酒劲吻你
借酒劲吻你 2020-11-27 06:26

I\'m curious why the String.indexOf is returning a 0 (instead of -1) when asking for the index of an empty string within a string.

The Javadocs only say this method

5条回答
  •  清歌不尽
    2020-11-27 07:15

    int number_of_empty_strings_in_string_named_text = text.length() + 1

    All characters are separated by an empty String. Additionally empty String is present at the beginning and at the end.

提交回复
热议问题