import java.util.*;public class hash1 {
public static void main (String args[]) {
Hashtable hash1 = new Hashtable();
Enumeration enum ;
int i = 0;
hash1.put("one",new Integer(1));
hash1.put("two",new Integer(2));
hash1.put("three",new Integer(3));
enum = hash1.keys();
while (enum.hasMoreElements()) {
Object key1 = enum.nextElement();
Object value1 = hash1.get(key1);
i ++;
System.out.println("Key:" + key1 + " " + "Value:" + value1);
}
System.out.println("HashTable.Size = " + i);
}
}
public static void main (String args[]) {
Hashtable hash1 = new Hashtable();
Enumeration enum ;
int i = 0;
hash1.put("one",new Integer(1));
hash1.put("two",new Integer(2));
hash1.put("three",new Integer(3));
enum = hash1.keys();
while (enum.hasMoreElements()) {
Object key1 = enum.nextElement();
Object value1 = hash1.get(key1);
i ++;
System.out.println("Key:" + key1 + " " + "Value:" + value1);
}
System.out.println("HashTable.Size = " + i);
}
}
里面有 enum 类型, 使用比较方便
要是楼主想试试的话推荐使用 sdk 1.5
虽然效率上跟传统方法差不多, 但是所需代码量大大减少
增强可读性, 看上去跟 C 的"外观"一样
String a = "";
int b =0;
byte c;
然后增加一些Set和Get方法,不增加的话,就把属性声明为
public的
public static final Enum 111 = new Enum("111"); public static final Enum 222 = new Enum("222"); public static final Enum 333 = new Enum("333"); public static final Enum 444 = new Enum("444"); public static final Enum 555 = new Enum("555"); private final String myName; // for debug only private Enum(String name) {
myName = name;
} public String toString() {
return myName;
}
}这是 IDEA 自动生成的 Enum 类型
你可以参考一下