62,620
社区成员
发帖
与我相关
我的任务
分享
String [] aa = {"hello","world"};
String temp = aa.toString();
System.out.println(aa);
System.out.println(temp);
System.out.println(Arrays.deepToString(aa));
有很多类重写了hashCode方法
比如 HashMap就重写了hashCode方法
//Map里的方法
public int hashCode() {
int h = 0;
Iterator<Entry<K,V>> i = entrySet().iterator();
while (i.hasNext())
h += i.next().hashCode();
return h;
}
//Map.Entry里的方法
public int hashCode() {
return (key == null ? 0 : key.hashCode()) ^
(value == null ? 0 : value.hashCode());
}
public static void main(String[] args) {
HashMap map1 = new HashMap();
map1.put("a", "aaa");
HashMap map2 = new HashMap();
map2.put("a", "aaa");
System.out.println(map1.hashCode() + " " + map2.hashCode());
}