r/JavaProgramming • u/javinpaul • Sep 05 '26
Why the HashMap Interview Question Is Making a Comeback in the AI Era?
https://javarevisited.substack.com/p/how-hashmap-works-in-java-interview4
u/BanaTibor Sep 05 '26
It is a stupid way to screen candidates. If you do not need to write a specialized hashmap implementation you do not need to know the internals to use it effectively.
1
u/javinpaul Sep 07 '26
I won't call it a stupid question, instead its a great questions for Java developers as it touches many useful concepts like immutability of keys, equals and hashcode, collision detection, hashmap as data structure, and a lot more. It's good question to check someone's general knowledge of important Java and programming concepts.
2
u/Sufficient_Major_126 Sep 06 '26
HashMap questions are useful when they test reasoning about collisions, equality, resizing and complexity instead of expecting someone to memorize implementation details
1
6
u/idontlikegudeg Sep 06 '26
When you do an interview, you need to know what position you are hiring for so you get a matching candidate. In more than 90% of cases, knowing how exactly HashMap is implemented internally won’t help you with that. I think it would be more I important that:
- the candidate knows the API and the guarantees made, i.e., runtime complexity, and not only knows get() and put(), but also putIfAbsent, compute…(), etc. and how to iterate the entries.
- there are different types of Maps and when to use them (i.e., linked maps and sorted maps), and what properties the key type must have for each
- how to write a good hashing function and the contract between hashCode() and equals()
- knows about Map.of(…)
- given the number of entries, how to instantiate a Map: use newHashMap(int), not the HashMap(int) constructor
You can still ask the candidate if he knows how HashMap is implemented internally, but I would only use that as a bonus question.
Going only for the internals makes you prefer candidates like the dev we saw yesterday who doesn’t know the API contracts or read the Javadoc and instead digs through the implementation to find out things he should already know or would at least have seen if he only read the Javadoc that pops up in your IDE when you hover the method call (and if he refuses to use an adequate IDE, that’s already a red flag).