Charles Sexton wrote:Is their a way to override the function to control the mapping of the buckets?
No (at least not with HashMap) and, as Paul says, why would you want to? The whole point of a "hashed" collection is that an object's location is
directly related to its hash, which is why they're so fast. Indeed the reason why 16 is the default, and internal capacity is increased by powers of two is that (theoretically) the hashcode only needs to be
masked in order to render a bucket index (although HashMap actually does a bit of other "bit mangling" stuff as well); and masking operations are
blisteringly fast - typically only one or two machine instructions.
However, if it's element
ordering that interests you, LinkedHashSet preserves elements in insertion order, and LinkedHashMap can maintain keys in other orders too - the most common one being "last used".
HIH
Winston