On Sat, 9 Apr 2022 15:25:47 GMT, XenoAmess <d...@openjdk.java.net> wrote:
> > Quick question: If the maps are intended to be fixed-size, can't the users > > just call `new HashMap<>(size, 1)`, increasing the growth factor to prevent > > growth? > > @liach this questions equals question : "why default load factor be 0.75 not > 1" In short, when larger the load factor, smaller memory use, and larger > hash-collide rate, larger crud time cost. when smaller the load factor, > larger memory use, and smaller hash-collide rate, smaller crud time cost. As > for why default load factor be 0.75 but not 1, it is historical to me. it is > already 0.75 when I first learn java and never changed then. But I guess > there be some empirical formula behind it. No. I mean when the growth factor is 1 and exactly `size` key-value pairs are put into the map, the map will not grow; but when it's 0.75, the map will preemptively grow erroneously. Changing the growth factor is effectively no-op for a hash map that will not have more elements added later during its usage. ------------- PR: https://git.openjdk.java.net/jdk/pull/7928