Home Help Java A Java error ArrayIndexOutofBoundsException
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java error ArrayIndexOutofBoundsException

Advertisement
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};
		System.out.println(b[6]);
		}
    }

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:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 13, 2013

Related Tutorials

Ask Questions?    Discuss: Java error: ArrayIndexOutofBoundsException  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com