This is a two part question:
It makes no guarantees as to the
The internal storage of a HashSet
is defined by an algorithm. It is not randomized.
The specification (API) does not specify any particular algorithm, other than it being hash-based. The implementation can choose any algorithm it wants, and is free to choose a different one in future versions.
However, being algorithm-based, it means that for any particular version of the implementation (Oracle vs IBM, 7 vs 8, ...), adding a particular set of values will always produce the same result, i.e. ordering.
The ordering is consistent for a specific version, but it is undefined and subject to change without notice in future versions and/or different implementations, so you should never rely on order.