While working with arrays we get this exception many time , we try our best to solve this problem but we are not able to find out the actual solution of this . Because the reason behind that we are not getting the solution is ,”we don’t know that from where this exception is arising . so here we are going to discuss about the ArrayindexoutofBounds error of exception .
ArrayindexoutofBounds exception is a run time exception which is happens when we are trying to access that position in the array which is not declare or not in the reach of JVM . There for as Java is very friendly language. It will show the problem of not getting that particular index value in the form of exception . so that programmer can understand what Is wrong in his program .
Solution for this problem
As we have discussed that this problem arise due to accessing the undesirable position in the array . To solve this problem you can check your code that where this is happening and correct that array size of array and your program will run correctly .
As you can see in the program we have array which having 13 elements “softwoodcoder” and we are trying to access the 13th index position which is actually does not exist in the array because array index start from 0 . There for the last index value become in this condition is 12 and we are running loop to 13th level there for when loop run at 13th index of array and it will not find any value then it will get the Exception .
Now here in this we have limited the loop at 12th level so that it only runs at required position and the exception will not arise .
Here we have used very simple example to describe arrayindexoutofbounds .But If you still get any difficulties in these kinds problems lets us know we will work together to solve .