ArrayStoreException in Java Last Updated : 10 Oct, 2018 Comments Improve Suggest changes Like Article Like Report ArrayStoreException in Java occurs whenever an attempt is made to store the wrong type of object into an array of objects. The ArrayStoreException is a class which extends RuntimeException, which means that it is an exception thrown at the runtime. Class Hierarchy: java.lang.Object ↳ java.lang.Throwable ↳ java.lang.Exception ↳ java.lang.RuntimeException ↳ java.lang.ArrayStoreException Constructors of ArrayStoreException: ArrayStoreException(): Constructs an ArrayStoreException instance with no detail message. ArrayStoreException(String s): Constructs an ArrayStoreException instance with the specified message s. When does ArrayStoreException occurs? ArrayStoreException in Java occurs whenever an attempt is made to store the wrong type of object into an array of objects. Below example illustrates when does ArrayStoreException occur: Since Number class is a superclass of Double class, and one can store an object of subclass in super class object in Java. Now If an integer value is tried to be stored in Double type array, it throws a runtime error during execution. The same thing wouldn’t happen if the array declaration would be like: Java public class GFG { public static void main(String args[]) { // Since Double class extends Number class // only Double type numbers // can be stored in this array Number[] a = new Double[2]; // Trying to store an integer value // in this Double type array a[0] = new Integer(4); } } Runtime Exception: Exception in thread "main" java.lang.ArrayStoreException: java.lang.Integer at GFG.main(GFG.java:13) How to handle with ArrayStoreException? One can use try-catch block in Java to handle ArrayStoreException. Below example illustrates how to handle ArrayStoreException: Java public class GFG { public static void main(String args[]) { // use try-catch block // to handle ArrayStoreException try { Object a[] = new Double[2]; // This will throw ArrayStoreException a[0] = 4; } catch (ArrayStoreException e) { // When caught, print the ArrayStoreException System.out.println("ArrayStoreException found: " + e); } } } Output: ArrayStoreException found: java.lang.ArrayStoreException: java.lang.Integer Comment More infoAdvertise with us Next Article ArrayStoreException in Java S Sruti Rai Follow Improve Article Tags : Misc Java Java-Exceptions Java-Exception Handling Practice Tags : JavaMisc Similar Reads Errors V/s Exceptions In Java In Java, errors and exceptions are both types of throwable objects, but they represent different types of problems that can occur during the execution of a program. Errors are usually caused by serious problems that are outside the control of the program, such as running out of memory or a system cr 5 min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt 10 min read Array Index Out Of Bounds Exception in Java In Java, ArrayIndexOutOfBoundsException is a Runtime Exception thrown only at runtime. The Java Compiler does not check for this error during the compilation of a program. It occurs when we try to access the element out of the index we are allowed to, i.e. index >= size of the array.Java supports 4 min read Collections Class in Java Collections class in Java is one of the utility classes in the Java Collections Framework. The java.util package contains the Collections class in Java. The Java Collections class is used with the static methods that operate on the collections or return the collection. All the methods of this class 13 min read Like