title: Array Problems java.lang.ArrayIndexOutOfBoundsException: 9
body: <p>I am trying to write a class that takes a phone number that the user inputs as a string, then stores each digit in an array. I converted the string to a long using Long.parseLong. Here is the function that is supposed to store each individual digit in an array. </p>
  
  <pre><code>public void storetoarray()
          //Turn the strings to longs
          //A loop chops of the last digit and stores in an array
  {
      phonelong = Long.parseLong(initialphone);
      phonetemp1 = phonelong;
      for (int i = phonelength; i&gt;=0; i--)
      {
          phonearray[i-1] = phonetemp1%10;
          phonetemp2 = phonetemp1 - phonetemp1%10;
          phonetemp1 = phonetemp2/10;
          System.out.print("Phone temp 2" + phonetemp2 + phonetemp1);
      }
  }
  </code></pre>
  
  <p>The logic of that loop is to find the last digit of the phone number using a %10, then subtract that number from the original phone number. That new difference is then set to be phonetemp1/10.</p>
  
  <p>Example 4158884532%10 = 2. That is stored in phonearray[9]. Then phonetemp2 is subtracted giving us 4158884530. Divide that by 10 and you get 415888453. Should be ready to store the next digit. </p>
  
  <p>What is going wrong? Thanks for the help!</p>