why use \0 to include highEndPoint as part of the sublist

后端 未结 2 702
鱼传尺愫
鱼传尺愫 2021-01-20 18:58

I saw the code below from java tutorial oracle. In order to count the number of words between doorbell (inclusive) and pickle(inclusive), the autho

2条回答
  •  [愿得一人]
    2021-01-20 19:37

    I believe \0 is the null character. The next word in the ASCII dictionary from a lexigraphic point after the word pickle is pickle\0. The JavaDoc for SortedSet.subset() has the following to say:

    Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.

    In other words, if your code snippet were the following:

    int count = dictionary.subSet("doorbell", "pickle").size();
    

    then the word pickle would not appear in the subset.

    A better example might be if you wanted to get all words of the form pickles, but nothing of the form picklet (ending in t), then you would use the following code:

    int count = dictionary.subSet("doorbell", "picklet").size();
    

    Here is a link to the ASCII character table.

提交回复
热议问题