- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
考虑以下代码:
byte[] bytes = new byte[] { 1, 2, 5, 0, 6 };
byte[] another = new byte[] { 1, 2, 5, 0, 6 };
Hashtable ht = new Hashtable();
ht.Add(bytes, "hi");
Assert.IsTrue(ht.ContainsKey(another));
为什么这个断言会失败?作为原始类型的数组不应该使用对象引用,不是吗?那么为什么它会返回 false 呢?我可以做些什么来使这个哈希表正常工作吗?
最佳答案
Being an array of a primitive type shouldn't use using the object reference, should it?
是的,它应该。数组是引用类型。
一切正常。
如果您想要不同的行为,您可以为数组实现一个比较器来比较内容并将其传递给哈希表。
关于c# - 为什么对于 C# 中 byte[] 类型的键,哈希表不会为 "ContainsKey"返回 true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1905038/
java.util.Map.containsKey(Object key)文件说: @throws ClassCastException if the key is of an inappropria
我正在为大学类(class)实现一个 Web 项目,该项目使用 struts2,当我运行该项目时,它会在 containsKey() 中阻塞。它不打印任何字符串。 这是我遇到问题的一些代码: pack
我的字典的 ContainsKey() 方法不起作用 - 我如何“覆盖 GetHashCode()”以使其起作用? 最佳答案 您必须同时覆盖 GetHashCode()和 Equals()来表示等价。
我正在尝试将超链接存储为 map 中的键,我正在使用 multimap private Map> record=new HashMap>(); 我正在使用以下方法检查超链接是否已经存在于 map 中
好的,我需要一点帮助。我有一本通用词典“cashdata”。这个字典的键是对象(查询对象,我定义的一个类)。查询对象有“Terms”字段,它是一个字符串列表,和一个“Operator”字段,它是一个枚
我在用 gradle 构建我的 Android 项目时遇到了这个错误。它大约每周发生一次。 FAILURE: Build failed with an exception. * What went w
尝试实现陷入奇怪问题的简单任务: class User{ String login; String pwrd; User(String lg,String pw){
使用此代码时出现崩溃: if (!savedInstanceState.containsKey("mybool")) { // my code } 我的onCreate(): @Overri
我正在用 java 编写 HashMap 的实现,但在 containsKey 方法中查找正确的存储桶时遇到了一些问题 public class MyHashMap { LinkedList[] ta
构造函数接受两个数组,我想将它们放入我的 HashMap 中,但如果映射已经包含其中一个数组中的单词,那么我想抛出异常。除非重复项是数组项中的最后一项,否则这种方法有效。为什么会发生这种情况? pri
程序将根据If语句打印不正确的键和值。有人能解释一下为什么吗? 例如键 = 汤姆叔叔 + 值 = 02086542222 键 = Harry + 值 = 020826262 查询=汤姆叔叔 返回 =
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在尝试将位置列表中的所有唯一坐标添加到单个 HashMap 中,该 HashMap 将坐标作为键,将计数作为值。关键是由“$”符号连接的经度和纬度。 //String = coordinates
This question already has answers here: Java HashMap containsKey returns false for existing object (
这个问题已经有答案了: What is the Java ?: operator called and what does it do? (17 个回答) Can Java's ternary/con
我基本上是在尝试将一些组织的 ID 和名称缓存在字典中。我不断收到错误消息:Item with Same Key has already been added。这对我来说很奇怪,因为第一个 if bl
我正在为一个使用家庭概念的应用程序创建一个插件。每个 Family 都属于一个 FamilyCategory,每个 Family 都包含 FamilySymbols。像这样的漂亮树结构: 家庭类别(门
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 7 年前。 我对 Java 很陌生。尝试访问
这是我的代码: import java.util.HashMap; class MyString { String string; MyString(String string) {
请解释字典的'getAt'方法失败的原因 List infoKeys = new List(infoDict.Keys); if (infoKeys.Contains(TorrentFileKeyWo
我是一名优秀的程序员,十分优秀!