title: Are upper bounds of indexed ranges always assumed to be exclusive?
body: <p>So in Java, whenever an indexed range is given, the upper bound is almost always exclusive.</p>
  
  <p>From <code>java.lang.String</code>:</p>
  
  <blockquote>
    <p><a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html#substring%28int,%20int%29" rel="nofollow noreferrer"><code>substring(int beginIndex, int endIndex)</code></a></p>
    
    <p>Returns a new string that is a substring of this string. The substring begins at the specified <code>beginIndex</code> and extends to the character at index <code>endIndex - 1</code></p>
  </blockquote>
  
  <p>From <code>java.util.Arrays</code>:</p>
  
  <blockquote>
    <p><a href="http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#copyOfRange%28T%5B%5D,%20int,%20int%29" rel="nofollow noreferrer"><code>copyOfRange(T[] original, int from, int to)</code></a>   </p>
    
    <p><code>from</code> - the initial index of the range to be copied, inclusive<br>
     <code>to</code> - the final index of the range to be copied, exclusive.</p>
  </blockquote>
  
  <p>From <code>java.util.BitSet</code>:</p>
  
  <blockquote>
    <p><a href="http://java.sun.com/javase/6/docs/api/java/util/BitSet.html#set%28int,%20int%29" rel="nofollow noreferrer"><code>set(int fromIndex, int toIndex)</code></a></p>
    
    <p><code>fromIndex</code> - index of the first bit to be set.<br>
    <code>toIndex</code> - index after the last bit to be set. </p>
  </blockquote>
  
  <p>As you can see, it does look like Java tries to make it a consistent convention that upper bounds are exclusive.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Is this the official authoritative recommendation?</li>
  <li>Are there notable violations that we should be wary of?</li>
  <li>Is there a name for this system? (ala "0-based" vs "1-based")</li>
  </ul>
  
  <hr>
  
  <p>CLARIFICATION: I fully understand that a collection of <code>N</code> objects in a 0-based system is indexed <code>0..N-1</code>. My question is that if a range <code>(2,4)</code> given, it can be either 3 items or 2, depending on the system. What do you call these systems?</p>
  
  <p>AGAIN, the issue is not "first index <code>0</code> last index <code>N-1</code>" vs "first index <code>1</code> last index <code>N</code>" system; that's known as the 0-based vs 1-based system.</p>
  
  <p>The issue is "There are 3 elements in <code>(2,4)</code>" vs "There are 2 elements in <code>(2,4)</code>" systems. What do you call these, and is one officially sanctioned over the other?</p>