先看下面的一個例子,假如你能毫不猶豫的全部答對,說明你對HashMap基本理解.
for(int i=0;i<20;i++) map.put(new Object(),new Object());
//這里加一些無用信息,導致rehash過程
System.out.println(map.get(k)!=null); //?
System.out.println(map.get(new Key(10))!=null); //?
System.out.println(map.get(new Key(11))!=null); //?
k.i--;//這里把Key改回去了
System.out.println(map.get(k)!=null); //?
System.out.println(map.get(new Key(10))!=null); //?
System.out.println(map.get(new Key(11))!=null); //?
}
static class Key
{
int i;
Key(int i){
this.i=i;
}
public boolean equals(Object obj){
新聞熱點
疑難解答