title: Converting Object to Double in Java
body: <p>I'm trying to deal with a lot of ClassCastExceptions in my code that are originating from a single critical point. I'll start with providing some background information for this question</p>
  
  <p>I'm reading different types of values from a csv file. The following is a snapshot of the class that holds them.</p>
  
  <pre><code>public class Row {
  private Object[] data;
  
  public Object getAtIndex(int i)
  {
      return data[i];
  }
  }
  </code></pre>
  
  <p>For holding the different rows of a file, I'm using a</p>
  
  <pre><code>ArrayList&lt;Row&gt; rows;
  </code></pre>
  
  <p>The <strong>problem</strong> lies in a function which is <strong>supposed to return a Double[] containing values of a particular column stored in the ArrayList</strong>. My current function looks like this</p>
  
  <pre><code>public Double[] getByIndex(int i)
      {
          Double[] result = new Double[rows.size()];
          String temp;
          for(int j=0;j&lt;rows.size();j++)
          {
              temp =(String)rows.get(j).getAtIndex(i); //java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
              result[j]=Double.parseDouble(temp);
          }
          return result;
      }
  </code></pre>
  
  <p>This getByIndex() is throwing ClassCastExceptions when called. I'm making sure that I call this function for only those columns which are expected to have Double values. 
  Is there any other way to facilitate this Object to Double conversion. My progress is stalled because of this problem.
  Please help.</p>