View RSS Feed

My Java Tips


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


Java Code:
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 Submit "ArrayStoreException" to StumbleUpon Submit "ArrayStoreException" to Google

Java SE