title: In Java, can you use negative one with substring?
body: <p>Can negative one be used as the end index for string.substring in Java?</p>
  
  <p>Example:</p>
  
  <pre><code>String str = "test";
  str.substring(0, str.indexOf("q"));
  </code></pre>
  
  <p>Edit: Nowhere in the javadocs does it say directly that <strong>endindex</strong> cannot be negative. There are implementations of substring in other languages and libraries that allow a negative endindex but <strong>disallow</strong> a negative beginindex, so it seems relevant that this be explicitly stated. It is not in any way implied either. (Edit: ok it is implied loosely, but I and apparently others who have asked me this question in person still find it pretty unclear. This was meant to be a simple Q+A that I provided not me actually trying to find an answer to this trivial question)</p>