Scrivio Interview library
ConceptIntermediate7 min read · updated 12 November 2026

When would you change HashMap's load factor from 0.75, and what do you trade by going to 0.5 or to 1.0?

Almost never. A lower load factor such as 0.5 leaves more empty buckets, so there are fewer collisions and slightly faster lookups, paid for with a larger table; a higher one such as 1.0 saves table memory but lets bins get longer, which mainly slows down lookups for keys that are not in the map. With a good hash function the default 0.75 already keeps the expected bin length well under one, so pre-sizing the map to avoid repeated resizes usually matters far more, and any change should be justified by a JMH benchmark with a realistic key distribution.

Why this question is asked

The load factor is one of the few tuning knobs HashMap offers, so it is natural to ask when to turn it. The honest answer is that the default is a good compromise and the gains from changing it are small and easy to misjudge. Interviewers ask this to see whether we can reason about the memory and time trade-off with numbers, and whether we know which optimisations actually matter. In this answer, we will recap what the load factor controls, calculate what 0.75 means for bin lengths, look at the memory side with real numbers, explain what 0.5 and 1.0 buy and cost, and finish with how to decide.

1A Quick Recap: What the Load Factor Controls

A HashMap keeps entries in buckets of an internal table. The load factor is the maximum ratio of entries to buckets the map allows before it doubles the table. With the default 0.75 and a table of 1024 buckets, the map holds up to 768 entries; the 769th causes a resize to 2048.

So the load factor sets two things at once: how many buckets, on average, each entry shares with others, which drives collisions and lookup time, and how big the table is for a given number of entries, which drives memory.

2What 0.75 Means for Bin Lengths

If hashes are well spread, entries fall into buckets roughly at random. The average number of entries per bucket is then the current ratio of size to capacity, which for a default map moves between 0.375 just after a resize and 0.75 just before the next one. The HashMap source notes that bin sizes then follow roughly a Poisson distribution, with about 60 percent of buckets empty, about 30 percent holding one entry and under 10 percent holding two or more at a ratio of 0.5.

For a lookup of a key that is present, the expected number of comparisons is about 1 + ratio / 2, so between about 1.2 and 1.4. For a miss, it is about the ratio itself, the number of nodes in the bucket we land on. Either way, less than two comparisons on average. That is the reason the default works well: there is very little left to gain.

Average nodes compared per lookup (good hash, ratio just before a resize)
Load factorHit (about 1 + a/2)Miss (about a)Table slots for 1,000,000 entries
0.51.250.52,097,152
0.75 (default)1.380.752,097,152
1.01.51.01,048,576
2.02.02.0524,288
Figures are rough averages; real maps sit between half and the full ratio.

3The Memory Side, With Real Numbers

Each bucket is one reference, 4 bytes with compressed references on a 64-bit JVM. Each entry is a Node of about 32 bytes, plus the key and value objects. So for a map of 1,000,000 entries, the Nodes alone are about 32 MB, while a table of 2,097,152 slots is about 8 MB.

Notice the last column of the table above: because capacity is always a power of two, 0.5 and 0.75 give the same table size for one million entries. One million is above 0.75 x 2^20 but at most 0.5 x 2^21, so both settings end at 2^21 slots. The load factor only changes the table at certain sizes. Going to 1.0 saves one doubling here, 4 MB out of a total of about 72 MB once the boxed keys and values are counted, around 5 percent.

Java
int n = 1_000_000;
Map<Long, Long> a = new HashMap<>(16, 0.75f); // grows to 2,097,152 slots: about 8 MB of table
Map<Long, Long> b = new HashMap<>(16, 0.5f); // also 2,097,152 slots for this n
Map<Long, Long> c = new HashMap<>(16, 1.0f); // 1,048,576 slots: about 4 MB of table
// Nodes: about 32 MB in every case, plus about 16 MB of boxed Long keys and 16 MB of values

So a higher load factor saves a modest share of the total, and a lower one costs a modest share, often nothing at all. Neither touches the bulk of the memory, which is in the entries.

4What 0.5 Buys and What 1.0 Costs

Going down to 0.5 gives each entry more room, so collisions are less frequent and bins are a little shorter. That helps most when lookups are dominated by misses, for example a filter map checked for every incoming event where most keys are not present, and when equals() is expensive, since each avoided collision avoids a call to it. The gain is from about 1.4 to about 1.25 node checks per hit, a few nanoseconds at best, and the cost is a larger table whenever the size falls in the range where it doubles.

Going up to 1.0 or beyond does the opposite. Bins get longer, so every lookup does a little more work, and misses suffer most because they must check every node in the bucket. A miss in a bucket with three nodes compares three stored hashes. If the keys have a weak hashCode(), the higher ratio makes clustering worse. The saving is limited to the table, a few MB per million entries.

5What Matters More: Pre-Sizing

A map that grows from 16 to two million slots goes through 17 resizes, each allocating a new table and moving every entry. Creating it with HashMap.newHashMap(expected), available since Java 19, avoids all of that. In real services, this saves more time and much more temporary memory than any change to the load factor, and it is a one-line change with no trade-off.

6How I Would Decide

I would leave 0.75 unless a profile shows that map lookups matter and a benchmark shows a change helps. The benchmark must use realistic keys, because the effect depends on the hash distribution and the hit-to-miss ratio. A JMH benchmark that builds the map at its real size and times get() for a production-like mix of hits and misses, at 0.5, 0.75 and 1.0, gives a clear answer in an afternoon. If a key class has a weak hashCode(), fixing hashCode() helps far more than any load factor.

Step throughShould we change the load factor?
  1. Do map lookups show up in the profile?
    YesLook closerNoLeave 0.75
  2. Is the map pre-sized?
    YesBenchmark load factorsNoPre-size first with newHashMap
  3. JMH with real keys and hit/miss mix0.5, 0.75, 1.0
  4. Clear, repeatable gain?
    YesChange it and document whyNoLeave 0.75

4 steps in order. Play them, or step through them one at a time.

7Follow-up questions

Can the load factor be greater than 1?

Yes. Any positive value is allowed, and with 2.0 the map holds on average two entries per bucket before it resizes. It saves table memory, but lookups get noticeably slower, and it only makes sense for very memory-constrained maps whose keys hash well.

Does ConcurrentHashMap honour a custom load factor?

Only partly. Its constructor accepts a load factor but uses it just to size the initial table; afterwards it resizes at a fixed ratio of about 0.75. So tuning the load factor of a ConcurrentHashMap has even less effect.

Why is a miss affected more than a hit?

A hit stops as soon as it finds the key, on average halfway through the bucket. A miss has to compare against every node in the bucket before it can say the key is absent, so longer bins cost it the full length.

8Conclusion

In this answer, we saw that the load factor trades table memory against collisions. A lower value such as 0.5 means more empty buckets and slightly faster lookups at the cost of a larger table, while 1.0 saves table memory but lengthens bins, which mostly hurts misses. With a good hash, 0.75 already keeps the expected bin length well under one, and because capacities are powers of two, a change often does not even alter the table size. Pre-sizing with HashMap.newHashMap matters more, and any change to the load factor should be backed by a JMH benchmark with a realistic key distribution.

What to say in the interviewAbout 90 seconds aloud

Open with

I would rarely change it. The load factor is the ratio of entries to buckets at which HashMap doubles its table, so it trades memory for collisions. At 0.5 there are more empty buckets, fewer collisions and slightly shorter bins, so lookups get a little faster, especially misses, but the table can be twice as big.

Then, if they want more

At 1.0 the table is smaller, but bins get longer, and misses suffer most because they must check every node in the bucket. With a decent hash function, 0.75 already keeps the average bin length below one: a hit compares about 1.4 nodes and a miss less than one, so there is little left to gain.

The memory side is also smaller than people expect. For a million entries the Nodes are about 32 megabytes, while the table at 0.75 is about 8 megabytes, and because capacity is a power of two, 0.5 actually gives the same 2 million slot table at that size. 1.0 would save about 4 megabytes.

What usually matters more is pre-sizing with HashMap.newHashMap, which avoids a long series of resizes and the memory spikes that come with them.

If a profile really showed map lookups as a hotspot, I would write a JMH benchmark with production-like keys and a realistic mix of hits and misses at 0.5, 0.75 and 1.0, and only change it if the gain was clear and repeatable, and I would document why.

About this answer

Last updated
12 November 2026
Versions it names
Java 19
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "When would you change HashMap's load factor from 0.75, and what do you trade by going to...": https://scrivio-interview-library.netlify.app/java/hashmap-internals/c38a41fde1/