title: How to convert Object[] filled with tokens to an Integer Array?
body: <p>I am trying to write a method that takes in an Object[] that is populated with tokens and converts it to an array of integers.  </p>
  
  <p>I started out with an ArrayList:</p>
  
  <pre><code>ArrayList&lt;String&gt; colArr = new ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>then populated it with tokens from a .txt file:</p>
  
  <pre><code>while(st.hasMoreTokens()){
      colArr.add(st.nextToken());
  }
  </code></pre>
  
  <p>then converted it to an Object[]:</p>
  
  <pre><code>Object[] newColArr = colArr.toArray();
  </code></pre>
  
  <p>I now need to write a method that converts this Object[] to an Integer so that I can add certain elements together.  This is what I tried:</p>
  
  <pre><code>public static Integer[] convert(Object[] objectArray){
      Integer[] intArray = new Integer[objectArray.length];
  
      for(int i=0; i&lt;objectArray.length; i++){
          intArray[i] = (Integer) objectArray[i];
      }
      return intArray;
  }
  </code></pre>
  
  <p>but got "<em>Error: java.lang.String cannot be cast to java.lang.Integer</em>".</p>