简体   繁体   English

Eclipse调试器中显示的哈希表值

[英]Hashtable values displayed in Eclipse debugger

在此输入图像描述 I am debugging a Hashtable in Eclipse and found something strange. 我在Eclipse中调试Hashtable并发现了一些奇怪的东西。 My Hashtable variable name is "my_hashTable", and Eclipse debugger, if I click it, it shows its values are three: {first=0, third=2, second=1}, which is correct as expected, and the count is 3, which is correct too. 我的Hashtable变量名是“my_hashTable”,而Eclipse调试器,如果我点击它,它显示它的值是三:{first = 0,third = 2,second = 1},这是正确的,并且计数是3 ,这也是正确的。

However, if I click the "table" variable inside the my_hashTable variable, it shows there are only two non-null values, [4] = 2 and [5] = 0. Its full values are below: 但是,如果我单击my_hashTable变量中的“table”变量,它会显示只有两个非空值,[4] = 2和[5] = 0.其完整值如下:

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

Why does this happen? 为什么会这样? Where is the "second=1" pair? “second = 1”对在哪里? This is the first time I encountered this odd observation in Eclipse. 这是我第一次在Eclipse中遇到这种奇怪的观察。

Any idea of what's going on? 知道发生了什么事吗? Thanks. 谢谢。

The above situation arises because of HashTable structure where table array stores the key-value pairs in the form of Map$Entry . 上述情况是由于HashTable结构而出现的,其中表数组以Map$Entry的形式存储键值对。 If two keys hash to the same bucket using the Object hashcode() and the underlying Collection's hashing algorithm ,they would be put in the same bucket(say table[j] )in the form of a singly-linked list using the next reference present in each Map$Entry Object .Thus.each table index contains a Map$Entry Object with a reference to next Map$Entry Object having the same hashbucket(but whose keys are unequal as per the equals() method of the Key Object).The thing is that the keys would be unequal as per the equals() method of the Key but their bucket index would be same using the hashcode() and hashing algorithm applied. 如果两个键使用Object hashcode() and the underlying Collection's hashing algorithm 散列到同一个桶 ,它们将使用下一个引用的目录单链表的形式放在同一个桶(比如table [j])中在每个Map $ Entry对象中 .The.each表索引包含一个Map$Entry对象,其中引用了具有相同hashbucket的下一个 Map$Entry对象(但其密钥根据Key Object的equals()方法是不相等的 )。问题是密钥根据Key的equals()方法是不相等的,但是using the hashcode() and hashing algorithm applied.它们的桶索引是相同using the hashcode() and hashing algorithm applied.

Just expand any of your visible table indexes for the next,and you would find the Key-value pair in the form of Map$Entry . 只需展开下一个可见的表索引,您就会发现Map$Entry形式的键值对。

Each Map$Entry stored in table array has the following structure:- 存储在表数组中的每个Map $ Entry具有以下结构: -

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

This is how Hash based collections work.Objects whose hashing algorithm return the same index are stored in the same bucket(table index) as a singular linked List. 这就是基于哈希的集合的工作方式。哈希算法返回相同索引的对象与单个链接列表存储在同一个存储桶(表索引)中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM