ArrayStoreException in Java Last Updated : 10 Oct, 2018 Comments Improve Suggest changes 1 Likes 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 Create Quiz Comment S Sruti Rai Follow 1 Improve S Sruti Rai Follow 1 Improve Article Tags : Misc Java Java-Exceptions Java-Exception Handling Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like