While reading about HashMap
I see that it is implemented as an array of buckets? Now are these buckets always linked lists? If so, why are they called buckets and not linked lists?
Looking at the source code of HashMap
tells us that it's implemented as an array of Entries:
transient Entry[] table;
Each Entry has a field next
, so they create a single linked list structure:
static class Entry<K,V> implements Map.Entry<K,V> {
final K key;
V value;
Entry<K,V> next;
"Bucket" is a higher-level term, used in the literature and when explaining hash maps. Here "buckets" are implemented as a single linked lists.
In Java's Hashmap, the buckets are implemented as a linked list (each Entry
has a reference to another entry called next
).
The term "bucket" is referring to a concept. Linked list an implementation detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With