title: How can I convert a Java HashSet<Integer> to a primitive int array?
body: <p>I've got a <code>HashSet&lt;Integer&gt;</code> with a bunch of <code>Integers</code> in it. I want to turn it into an array, but calling</p>
  
  <pre><code>hashset.toArray();
  </code></pre>
  
  <p>returns an <code>Object[]</code>. Is there a better way to cast it to an array of <code>int</code> other than iterating through every element manually?  I want to pass the array to</p>
  
  <pre><code>void doSomething(int[] arr)
  </code></pre>
  
  <p>which won't accept the Object[] array, even if I try casting it like </p>
  
  <pre><code>doSomething((int[]) hashSet.toArray());
  </code></pre>