Are upper bounds of indexed ranges always assumed to be exclusive?
- by polygenelubricants
So in Java, whenever an indexed range is given, the upper bound is almost always exclusive.
From java.lang.String:
substring(int beginIndex, int endIndex)
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
From java.util.Arrays:
copyOfRange(T[] original, int from, int to)
from - the initial index of the range to be copied, inclusive
to - the final index of the range to be copied, exclusive.
From java.util.BitSet:
set(int fromIndex, int toIndex)
fromIndex - index of the first bit to be set.
toIndex - index after the last bit to be set.
As you can see, it does look like Java tries to make it a consistent convention that upper bounds are exclusive.
My questions are:
Is this the official authoritative recommendation?
Are there notable violations that we should be wary of?
Is there a name for this system? (ala "0-based" vs "1-based")