title: Reusable method to transform Iterable<T> to T[]?
body: <p>I'm trying to write a generic method to return the contents of an Iterable in array form.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>public class IterableHelp
  {
      public &lt;T&gt; T[] toArray(Iterable&lt;T&gt; elements)
      {
          ArrayList&lt;T&gt; arrayElements = new ArrayList&lt;T&gt;();
          for(T element : elements)
          {
              arrayElements.add(element);
          }
  
          return (T[])arrayElements.toArray();
      }
  }
  </code></pre>
  
  <p>But I'm getting a compiler warning 'Note: ...\IterableHelp.java uses unchecked or unsafe operations.'</p>
  
  <p>Any thoughts on another approach that would avoid such a warning?</p>