For a test I need to create a set of numeric values. This can really be anything but for the sake of example let's say it is the numbers from 1 to 10,000 and I'll use a HashSet but anything implementing the Set interface is fine.
To do this I've done:
Set<Integer> set= new HashSet<>();
for (int i = 0; i < 10000; i++) {
set.add(i);
}
This gets me what I'm after but I'm wondering if there is a more efficient way. If the numbers were small I'd probably add them to an array by hand but that does not work here as 10,000 is too large. Thanks for any help.