-1

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?

2

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.