title: Convert list of strings to array of strings - difference between (String[])list.toArray() and list.toArray(new String[0])
body: <p>I have a <code>List&lt;String&gt;</code> in Java, and wanted to convert it to an array.</p>
  
  <p>At first, I used the toArray syntax that takes an array as input, but then I switched to the no-parameter version, i.e. I went from:</p>
  
  <pre><code>String[] myArray = myList.toArray(new String[0]);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>String[] myArray = (String[])myList.toArray();
  </code></pre>
  
  <p>Reading through the <a href="http://docs.oracle.com/javase/6/docs/api/index.html?java/util/ArrayList.html" rel="nofollow">documentation</a> (my underlying type is ArrayList), it seems that the functionality should be the same.  I thought the latter version was more efficient since it doesn't require allocating and collecting an empty array.  Am I missing any subtle differences?</p>
  
  <p>(Note: the reason I'm asking is that GWT does treat the statements differently.  The latter gives a dynamic cast error while the former does not.  I just wanted to know if this is a nuance of how I'm using GWT or a nuance of how I'm using Java.)</p>
  
  <p>Thanks!</p>