我的简单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 }}。您能提供清楚的信息吗?
答案 0 :(得分:4)
IDEA默认情况下具有简化的地图视图。要查看所有内部字段,您需要先对地图对象Right click
,然后对View as
-> Object
,然后对HashMap$Node
对象进行同样的操作。
关于table
的大小,默认情况下有16个存储桶:
java.util.HashMap#DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16
答案 1 :(得分:1)