Turn Desktop View Off
by Dinesh Thakur

ArrayStoreException is thrown when ever we storing something in an array. If we store wrong type object into an array then this will be thrown. Here is the Java example which explains this.

import java.io.*;

  class ArrayStoreExceptionJavaExample
  {
         public static void main(String aa[])  throws IOException
          {
                  BufferedReader BF= new BufferedReader(new InputStreamReader(System.in));
                  String Str;
                  int arr[]=new int[5];
                  int i,x;
                  System.out.println("Enter Five Number : ");
                  for(i=0;i<=4;i++)
                        {
                              Str=BF.readLine();
                              try
                               {
                                   arr[i]=Integer.parseInt(Str);
                               }
                                catch(NumberFormatException e)
                                        {
                                            System.out.println("Wrong data type enterd, try again");
                                            i--;
                                            continue;
                                        }
                       }
                                           System.out.println("Number Entered are :");
                                           x=0;
                                           while(true)
                                                    {
                                                      try
                                                            {
                                                              System.out.println(arr[x]);
                                                              x++;
                                                            }
                                                               catch(ArrayIndexOutOfBoundsException e1)
                                                                       {
                                                                           System.out.println("Number are Over:");
                                                                           return;
                                                                       }
                                                     }
           }
  }      

ArrayStoreException