Krishna Upadhyay
Krishna Upadhyay

Reputation: 29

How many pointers does java LinkedHashMap/Set Entry object have

In Java HashSet, when a collision occurs, the HashMap stores multiple entries in the same bucket using a linked list.

Then in the case of LinkedHashSet, LinkedHashMap will have a pointer to the next inserted element as well.

So, does each entry object have multiple pointers - one to point the elements in the same bucket and the other to point to the next inserted element?

Upvotes: -1

Views: 76

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198381

Technically, there are also pointers to the key and to the value. Look at the implementation and decide how many pointers count.

The answer you're probably looking for is three: one to the next in the bucket, one to the previous entry in insertion order, and one to the next entry in insertion order.

Upvotes: 3

Related Questions