title: Object[] cannot be converted to Integer[]
body: <p>Converting a TreeSet object to an array using the toArray method, however I get the error:<br>
      <code>Object[] cannot be converted to Integer[]</code></p>
  
  <p>Here is the code:</p>
  
  <pre><code>public static void main (String[] args) {
      TreeSet elems = new TreeSet&lt;Integer&gt;();
      int[] elemsToAdd = {1,2,3,4};
  
      for(int i = 0; i &lt; elemsToAdd.length; i++){
          elems.add(elemsToAdd[i]);
      }
      Integer[] elemsArray = elems.toArray(new Integer[elems.size()]);
   }
  </code></pre>
  
  <p>I've searched other threads for the answer, however all of them recommend to use the toArray method with an Integer array as an argument yet mine still throws an error.</p>