Hashtable values ​​displayed in the Eclipse debugger

enter image description here I am debugging a Hashtable in Eclipse and have discovered something strange. My Hashtable variable name is "my_hashTable" and the Eclipse debugger, if I click on it, it shows that its values ​​are three: {first = 0, third = 2, second = 1}, which is true, as expected, and the counter equal to 3, which is also correct.

However, if I clicked the "table" variable inside the my_hashTable variable, it shows that there are only two nonzero values, [4] = 2 and [5] = 0. Its full values ​​are below:

[null, null, null, null, third = 2, first = 0, null]

Why is this happening? Where is the "second = 1" pair? This is the first time I've come across this odd observation in Eclipse.

Any idea what is going on? Thanks.

+8
java hashtable debugging eclipse
source share
1 answer

The above situation arises from the HashTable structure, where an array of tables stores key-value pairs in the form of Map$Entry . If two hash hashes in the same bucket using Object hashcode() and the underlying Collection hashing algorithm , they will be placed in the same bucket (for example, table [j]) in a single- linked list using the following link in each $ map object . Thus, each table index contains a Map$Entry Object with a link to the next Map$Entry Object that has the same hash (but the keys are not equal according to the equals() method of the Key object). The fact is that the keys would be unequal in the key's equals () method, but their bucket index would be the same using the hashcode() and hashing algorithm applied.

Just expand any of your visible table indices for the next, and you will find a Key-value pair in the form of Map$Entry .

Each $ Entry Card stored in an array of tables has the following structure: -

 1)key 2)value 3)hashcode 4)next -contains reference of next Map$Entry 

This is how Hash collections work. Objects whose hashing algorithm returns the same index are stored in the same bucket (table index) as a single linked list.

+9
source share

All Articles