HashTable 是否维护广告顺序?
2022-09-02 02:26:37
下面的代码以相同的插入顺序为我提供输出。我读了javadoc,他们甚至没有谈论插入顺序。有人可以帮助我获得正确的信息吗?
import java.util.*;
public class hash {
public static void main(String[] args) {
String str[] = { "japan",
"usa",
"japan",
"russia",
"usa",
"japan",
"japan",
"australia"};
int len = 8;
Hashtable ht = new Hashtable();
int i = 0;
while (i < len) {
String c = str[i];
System.out.println("c :" + c);
Integer intg = (Integer) ht.get(c);
if (intg == null)
ht.put(c, new Integer(1));
else
ht.put(c, new Integer(intg.intValue() + 1));
i++;
}
Enumeration k = ht.keys();
while (k.hasMoreElements()) {
String key = (String) k.nextElement();
System.out.println(key + " > " + ht.get(key));
}
}
}