title: Java - Most efficient way to convert a TreeSet<String> into a String[]?
body: <p>I was doing this:</p>
  
  <pre><code>(String[]) myTreeSet.toArray();
  </code></pre>
  
  <p>but that gives me a ClassCastException at runtime. </p>
  
  <p>The only thing I can think of doing is just making an array first and then iterating through each element in myTreeSet and adding it to the array. It seems like there must be a better way than this. Is there or should I just do this?</p>
  
  <p>Thanks.</p>