IntelliJIdea:HashMap调试窗口未显示与链表有关的完整详细信息

时间:2018-08-14 13:20:36

标签: java intellij-idea

我的简单Java代码如下所示:

String s1 = "FB";

String s2 = "Ea";

System.out.println(s1.hashCode() == s2.hashCode()); // true

Map<String, Integer> map = new HashMap<>();

map.put(s1, 1);

map.put(s2, 2);

在IntelliJIdea中调试这段代码时,我看不到HashMap数据结构创建的链表,而且,尽管s1和{{1 }}。您能提供清楚的信息吗?

2 个答案:

答案 0 :(得分:4)

IDEA默认情况下具有简化的地图视图。要查看所有内部字段,您需要先对地图对象Right click,然后对View as-> Object,然后对HashMap$Node对象进行同样的操作。

enter image description here

关于table的大小,默认情况下有16个存储桶:

java.util.HashMap#DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

答案 1 :(得分:1)

您需要做三件事。 这不是直接的,我花了一段时间才弄清楚,因为以前没有人回答过。

您需要取消选中该值(如果已选中)。要打开该窗口,您需要在调试器内部右键单击,然后选择“ Customize Data Views ...”。 You need to uncheck that value if it is checked. To open that window you need to right click inside the debugger then chose "Customize Data Views..."

现在,您应该在该表中看到一个列表。

第二,您需要右键单击要查看其上的下一个节点的节点,然后选择“新类级别的监视”

Second you need to right click on the node that you want to see the next node on it and chose "new class level watch"

右键单击该节点,然后选择putMapEntries();。 right click on that node and chose putMapEntries();

您可以看到FB的下一个值为Ea As you can see the next value for  FB is Ea

我希望能有所帮助。