System.out.println("The hashtable hash1 is: "+hash);
System.out.println("The size of this hash table is"+hash.size());
//打印hash的内容和大小
Enumeration enum1=hash.elements();
System.out.print("The element of hash is: ");
while(enum1.hasMoreElements())
System.out.print(enum1.nextElement()+" ");
System.out.println();
//依次打印hash中的内容
if(hash.containsKey("Jiangsu"))
System.out.println("The capatial of Jiangsu is"+hash.get("Jiangsu"));
hash.remove("Beijing");
//删除关键字Beijing对应对象
System.out.println("The hashtable hash2 is: "+hash);
System.out.println("The size of this hash table is"+hash.size());
}
}
复制代码
运行结果:
The hashtable hash1 is: {Beijing=Beijing, Zhejiang=Hangzhou,Jiangsu=Nanjing}
The size of this hash table is 3
The element of hash is: Beijing Hangzhou Nanjing
The capatial of Jiangsu is Nanjing
The hashtable hash2 is: {Zhejiang=Hangzhou,Jiangsu=Nanjing}
The size of this hash table is 2作者: 袁梦希 时间: 2013-5-24 19:51