gpt4 book ai didi

java - 为什么 2 个不同 HashMap 的相同值的输出为 false?

转载 作者:行者123 更新时间:2023-11-29 04:39:31 25 4
gpt4 key购买 nike

代码:

public static void main(String[] args) {

HashMap<Integer, HashSet<Integer>>
map1 = new HashMap<Integer, HashSet<Integer>>(),
map2 = new HashMap<Integer, HashSet<Integer>>();
HashSet<Integer> set1=new HashSet<Integer>();
set1.add(1);
set1.add(2);
map1.put(1,set1);
map2.put(1,set1);
System.out.println(map1.values()==map2.values());
System.out.println(map1.values()+" "+map2.values());
}

最佳答案

比较Object数据类型是否相等的正确方法是使用方法equals()

map1.equals(map2);

关于java - 为什么 2 个不同 HashMap 的相同值的输出为 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39815488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com