title: Java Convert Generic LinkedList to Generic Array
body: <p>So for starters lets say that I have a <code>LinkedList&lt;String&gt;</code>, </p>
  
  <p>I can easily convert it to an array via <code>toArray()</code>. i.e.</p>
  
  <pre><code>LinkedList&lt;String&gt; strList = new LinkedList&lt;String&gt;();
  String[] strArray = strList.toArray(new String[0]);
  </code></pre>
  
  <p>But Lets say I have a <code>LinkedList&lt;T&gt;</code>
  Then I the following code:</p>
  
  <pre><code>LinkedList&lt;T&gt; tList = new LinkedList&lt;T&gt;();
  T[] strArray = tList.toArray(new T[0]);
  </code></pre>
  
  <p>I get the <b>Cannot create a generic array of T</b> error message. </p>
  
  <p>How can I get around this? </p>
  
  <p>Specifically in my class I have <code>LinkedList&lt;AbstractNode&lt;T&gt;&gt; nodes</code>, and I am trying to implement a getAll() method that returns all the nodes as an Array.<br/>
  Thanks!</p>
  
  <p><b>Note</b> Péter Török's answer provides the correct answer to my problem, but for me simply returning an ArrayList instead of [] as Bar mentioned, ended up smoothing my code out a lot.
  <br/><b>Note2</b> after looking at my code a bit more i'm not even sure if any conversion was necessary to begin with, LinkedList was fine for what I was trying to do... :-/</p>