先看下面的一个例子,假如你能毫不犹豫的全部答对,说明你对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){
新闻热点
疑难解答