title: How do I convert an ArrayList of generics (T) to a straight array?
body: <p>First time using generics.</p>
  
  <p>I've successfully created an ArrayList of generic objects, and I would like to convert it to a regular array <code>T[]</code>.</p>
  
  <p>Normally, this is something like</p>
  
  <pre><code>String[] x = (String[])myStrings.toArray(new String[0])
  </code></pre>
  
  <p>However, in this case, replacing String with <code>T</code> does not work. i.e.</p>
  
  <pre><code>return (T[]) ret.toArray(T[0]);
  </code></pre>
  
  <p>Here is complete code for my method, tho not sure it is relevant:
  <a href="https://puu.sh/AzxKD/f525bdbe77.png" rel="nofollow noreferrer">https://puu.sh/AzxKD/f525bdbe77.png</a></p>