I\'ve got a HashSet with a bunch of Integers in it. I want to turn it into an array, but calling
hashset.toArray();
You can create an int[] from any Collection (including a HashSet) using Java 8 streams:
int[] array = coll.stream().mapToInt(Number::intValue).toArray();
The library is still iterating over the collection (or other stream source) on your behalf, of course.
In addition to being concise and having no external library dependencies, streams also let you go parallel if you have a really big collection to copy.