title: ArrayList toArray method class cast exception
body: <p>I don't understand why this is giving me a class cast exception:</p>
  
  <pre><code>List&lt;String&gt; names = new ArrayList&lt;String&gt;();
  for (ApplicationInfo app : apps) {
      names.add("" + app.loadLabel(packageManager));
  }
  return (String[]) names.toArray();
  </code></pre>
  
  <p>the log is:</p>
  
  <p><code>01-23 16:56:18.746: E/AndroidRuntime(4027): Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]</code></p>
  
  <p>but I clearly defined <code>names</code> to be a list of <code>String</code> and not <code>Object</code></p>
  
  <p>**EDIT:</p>
  
  <p>oh wait, okay i see in the API it returns array of objects. how could i do this without doing:</p>
  
  <pre><code>List&lt;String&gt; names = new ArrayList&lt;String&gt;();
  for (ApplicationInfo app : apps) {
      names.add("" + app.loadLabel(packageManager));
  }
  String[] list = new String[names.size()];
  return names.toArray(list);
  </code></pre>
  
  <p>and making a new array each time?</p>