???????н?????£?
map.get(key) is :ddd
map.get(key) is :bbb
map.get(key) is :ccc
map.get(key) is :aaa
tab.get(key) is :bbb
tab.get(key) is :aaa
tab.get(key) is :ddd
tab.get(key) is :ccc
tmp.get(key) is :aaa
tmp.get(key) is :bbb
tmp.get(key) is :ccc
tmp.get(key) is :cdc

????HashMap?????????????????TreeMap????????????????
????????????????????????????????????????????HashMap:

 

import java.util.*;
public class Exp1 {
public static void main(String[] args){
HashMap h1=new HashMap();
Random r1=new Random();
for (int i=0;i<1000;i++){
Integer t=new Integer(r1.nextInt(20));
if (h1.containsKey(t))
((Ctime)h1.get(t)).count++;
else
h1.put(t?? new Ctime());
}
System.out.println(h1);
}
}
class Ctime{
int count=1;
public String toString(){
return Integer.toString(count);
}
}

??????HashMap?????get()?????value?????put()??????value??ContainsKey()???????????????????????????????????ArrayList?????????HashMap???????key??????????????????????????
?????????????HashMap?????HashCode????????ж???????Object???????HashCode()??????????????equals????????????????????????е???????????????????д?????HashCode()???????????????????????

 

import java.util.*;
public class Exp2 {
public static void main(String[] args){
HashMap h2=new HashMap();
for (int i=0;i<10;i++)
h2.put(new Element(i)?? new Figureout());
System.out.println("h2:");
System.out.println("Get the result for Element:");
Element test=new Element(5);
if (h2.containsKey(test))
System.out.println((Figureout)h2.get(test));
else
System.out.println("Not found");
}
}
class Element{
int number;
public Element(int n){
number=n;
}
}
class Figureout{
Random r=new Random();
boolean possible=r.nextDouble()>0.5;
public String toString(){
if (possible)
return "OK!";
else
return "Impossible!";
}
}