所以在Java中,无论何时给出索引范围,上限几乎总是独占的.
来自java.lang.String:
07000
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1
来自java.util.Arrays:
07001
from – the initial index of the range to be copied, inclusive
to – the final index of the range to be copied, exclusive.
来自java.util.BitSet:
07002
fromIndex – index of the first bit to be set.
toIndex – index after the last bit to be set.
正如您所看到的,它看起来像Java试图使其成为上限是独占的一致约定.
我的问题是:
>这是官方权威推荐吗?
>是否存在我们应该警惕的明显违规行为?
>这个系统有名字吗? (ala“0-based”vs“1-based”)
澄清:我完全理解基于0的系统中的N个对象的集合被索引为0..N-1.我的问题是,如果给定范围(2,4),它可以是3项或2,具体取决于系统.你怎么称呼这些系统?
再次,问题不是“第一指数0最后指数N-1”与“第一指数1最后指数N”系统;这就是所谓的基于0和基于1的系统.
问题是“(2,4)”中有3个元素与“(2,4)”系统中有2个元素.你怎么称呼这些,并且正式批准另一个?