Java error ArrayIndexOutofBoundsException

When an array has been accessed with an illegal index, which doesn't exist then ArrayIndexOutofBoundsException is thrown.

Java error: ArrayIndexOutofBoundsException

In this section you will get details about ArrayIndexOutofBoundsException java. This exception generally occurs when accessing to an illegal array index. The index is either greater or equal to the size of array. Suppose you have created an array with size of five and trying to access the sixth array element which does not exist, then it will throw an ArrayIndexOutofBoundsException. It means that you have created a array which store five value and you are trying to access the sixth element which doesn't exist.

Example: Code to show the ArrayIndexOutofBoundsException error

public class ArrayIndex {
	public static void main(String args[])
		int b[]={10,20,30,40,50};

In the above code, creating an array with size five which contain five integer element and printing the sixth element which does not exist. So, it will throw a exception ArrayIndexOutofBoundsException.

Output : When you will compile and execute then output will look like as below:

Share on Google+Share on Google+

Java error ArrayIndexOutofBoundsException

Posted on: June 13, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Java error: ArrayIndexOutofBoundsException  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image