Skip to content
Preptima

Collections Framework interview questions

Implementation internals, resizing behaviour, ordering guarantees, and choosing the right collection.

4 questions in Java & Spring.

easy1

medium3

mediumConceptCoding

Sorting a list throws IllegalArgumentException saying the comparison method violates its general contract. What did the comparator get wrong?

The sort detected that your comparator contradicted itself partway through a merge. The usual causes are a subtraction that overflows, an ordering that is not transitive, and a sort key that changes while the sort is running. Use this collections answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects sorting to the point an interviewer is testing.

5 minmid, senior, staff
mediumConcept

How does HashMap work internally, and what happens when it resizes?

HashMap stores entries in an array of buckets indexed by a hash of the key; collisions chain into a linked list that converts to a red-black tree past a threshold, and exceeding the load factor triggers a resize that reallocates and redistributes every entry. It also connects collections to the point an interviewer is testing.

3 minentry, mid, senior