58,454
社区成员
发帖
与我相关
我的任务
分享
import java.util.Enumeration;
import java.util.Hashtable;
/**
* Description:
*
* @author
* @Date 2017年10月18日
*/
public class HashApp {
public static void main(String args[]) {
Hashtable<String,String> hash = new Hashtable<String,String>(2, (float) 0.8);
hash.put("jiangsu", "Nanjing");
hash.put("Bejing", "Bejing");
hash.put("zhejiang", "Hanfzhou");
System.out.println("The hashtable hash1 is:" + hash);
System.out.println("The size of this hash table is" + hash.size());
Enumeration<String> enuml = hash.elements();
System.out.println("The element of hash is:");
while (enuml.hasMoreElements()) {
System.out.println(enuml.nextElement() + " ");
System.out.println();
}
if (hash.containsKey("Jiangsu")) {
System.out.println("The capatial of Jiangsu is "
+ hash.get("Jiangsu"));
hash.remove("Bejing");
System.out.println("The hashtable hash2 is:" + hash);
System.out.println("The size of this hash table is" + hash.size());
}
}
}
可以运行的,结果是
The hashtable hash1 is:{jiangsu=Nanjing, zhejiang=Hanfzhou, Bejing=Bejing}
The size of this hash table is3
The element of hash is:
Nanjing
Hanfzhou
Bejing
看看你的代码是不是少了“{“,”}”