title: Java - Mixed ArrayLists?
body: <p>Is it possible to store a mixture of object types in an ArrayList? If so how?</p>
  
  <p>This is what I have tried so far:</p>
  
  <pre><code>List&lt;Object&gt; list = new ArrayList&lt;Object&gt;();
  
  list.add(new String("Hello World"));
  list.add(new Integer(1));
  list.add(new Long(1l));
  
  for (i = 0; i &lt; list.size(); i++) {
      if (list.get(i) instanceof String){
          sqlPreparedStatement.setString((i+1), (String) list.get(i));
      } else if (list.get(i) instanceof Integer) {
          sqlPreparedStatement.setInt((i+1), (Integer) list.get(i));
      } else if (list.get(i) instanceof Long) {
          sqlPreparedStatement.setLong((i+1), (Long) list.get(i));
      }
  }
  </code></pre>
  
  <p>But it throws a casting exception.</p>
  
  <p>Thanks in advance for any input!</p>