Reference: http://blog.csdn.net/javaeeteacher/article/details/4485834
http://bbs.csdn.net/topics/90298133
This is a very common exception, from the name of the array subscript out-of-bounds error, the workaround is to see why the subscript is out of bounds.
The following is an example of an error:
Exception in thread "main" Java.lang.arrayindexoutofboundsexception:2
At Test4. State.nextstates (state.java:93)
At Test4. State.main (state.java:478)
The following information can be obtained from these hints:
1, error occurred in 93 lines
2. When an error occurs, the underlying value is 2
The next step is to analyze why the subscript value is 2 and can be solved.
Own understanding of:
That's actually the problem with the array out of bounds.
The array assignment in Java is the space from 0 to its length-1,
Example:
int []a={1,2,3,4,5};
It allocates 5 spaces, so the definition is like this one.
int [5]a={1,2,3,4,5}
is the same, but you can't call a[5], only call to A[4]
Results: a[0]=1,a[1]=2,a[2]=3,a[3]=4,a[4]=5,
But using: a[5]= array out of bounds
Analysis and solution of java.lang.ArrayIndexOutOfBoundsException anomaly