title: Reason for subtracting substring()'s endIndex by 1
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6339158/why-from-index-is-inclusive-but-end-index-is-exclusive">why from index is inclusive but end index is exclusive?</a>  </p>
  </blockquote>
  
  
  
  <p><code>substring()</code> method => <code>String substring(int beginIndex, int endIndex)</code></p>
  
  <p>Description:</p>
  
  <blockquote>
    <p>Returns a new string that is a substring of this string. The first
    integer argument specifies the index of the first character. The
    second integer argument is the index of the last character - 1.</p>
  </blockquote>
  
  <p>Take a look at the following code:</p>
  
  <pre><code>String anotherPalindrome = "Niagara. O roar again!"; 
  String roar = anotherPalindrome.substring(11, 15); 
  </code></pre>
  
  <p>Output: <code>roar</code></p>
  
  <p>Now, if the JVM didn't substract <code>int endIndex</code> by one, we could just use <code>substring(11,14)</code> instead, wouldn't that be much more convenient and less error-prone (human side)? Had you not read the description carefully, you might just ended up scratching your head for half an hour (like I did) when you thought that <code>endIndex</code> is just the normal index. What's the reason for the Java language creators to subtract it by one? </p>