title: How can I avoid ArrayIndexOutOfBoundsException or IndexOutOfBoundsException?
body: <p>If your question is <em>I am getting a <code>java.lang.ArrayIndexOutOfBoundsException</code> in my code and I do not understand why it is happening, what does it mean and how can I avoid it?</em></p>
  <blockquote>
  <p>This is meant to be the most comprehensive <a href="https://meta.stackoverflow.com/a/291994/177800">canonical</a> collection of information on this
  <code>java.lang.ArrayIndexOutOfBoundsException</code> topic as well as the <code>java.lang.IndexOutOfBoundsException</code>.</p>
  </blockquote>
  <p>There are many questions like this and all of them have either vague no-code answers, or mostly they are extremely specific and localized to the question at hand and do not address the root cause which is exactly the same in all cases.</p>
  <hr />
  <blockquote>
  <p><em>If you see one that falls under this general case, rather than answer it with more duplicate specialized content, mark it as a duplicate of this one.</em></p>
  </blockquote>