why from index is inclusive but end index is exclusive?

后端 未结 4 819
有刺的猬
有刺的猬 2020-12-16 11:51

In Java API methods like:

  • String.substring(int beginIndex, int endIndex)
  • String.subSequence(int beginIndex, int endIndex)
4条回答
  •  渐次进展
    2020-12-16 12:28

    In addition to what Bohemian said:

    If it were exclusive, to get the first 4 characters in a String, you'd have to:

    String firstFour = String.substring(0, 3);

    That's rather ugly.

提交回复
热议问题