HashMap
的键是一个 String[]
数组:HashMap<String[], String> pathMap;
您能否通过使用新创建的String[]
数组访问地图,还是必须使用相同的String[]
对象?
pathMap = new HashMap<>(new String[]{"korey", "docs"}, "/home/korey/docs");
String path = pathMap.get(new String[]{"korey", "docs"});
hashCode()
来确定对象的哈希值。 - pvorbhashCode()
的两个引用将使用equals()
进行比较,以确定它们是否是相同的键。 - Ted HoppList
是否符合您的需求。请看我的编辑答案。 - Ted HoppHashMap.containsKey
不需要键实现Comparable
接口。它只依赖于hashCode()
和equals()
方法。你的代码中一定还有其他问题。 - Ted Hopp