View RSS Feed

My Java Tips

ArrayStoreException

Rate this Entry
by , 05-24-2011 at 02:48 PM (5507 Views)
java.lang.ArrayStoreException is a runtimeException and is thrown when we try to store wrong type of object into an array of objects.

Constructors:

Java Code:
ArrayStoreException()
ArrayStoreException(String s)
For example: Storing an Integer object in a Strign array will cause this exception.

Java Code:
Object x[] = new String[3];
x[0] = new Integer(0);
Since its a runtime exception, compiler won't complain about this at compile time. It will be thrown at runtime. Solution is to store only object of supported types into an array.

Of course, an array of type A can store objects of type B if B extends A.

Hope this helps.

Submit "ArrayStoreException" to Facebook Submit "ArrayStoreException" to Digg Submit "ArrayStoreException" to del.icio.us Submit "ArrayStoreException" to StumbleUpon Submit "ArrayStoreException" to Google

Categories
Java SE

Comments