Java Data StructuresLesson 70Free preview
Java HashMap
This lesson is part of Java · All levels
Summary
HashMap is the most commonly used Map implementation because it searches for keys using hashing with average O(1). The key sequence is uncertain, and the key must have a consistent hashCode() and equals() to keep the data from getting lost. This structure is suitable for key mapping to frequently read and written values.
Key points
- Get, put, and remove running average, with worst-case
- Allows one key and a number of values
- Not sequential; select LinkedHashMap when the input sequence needs to be maintained
- The default capacity is 16 and the load factor is 0.75 before the resize occurs
- The key should be immutable so that the location in the bucket does not change.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.