Hashtable中put进去的对象是否保持put的顺序
下边是代码
Hashtable hs = new Hashtable();
hs.put("1","one");
hs.put("2","two");
hs.put("3","three");
Enumeration enumeration = hs.elements();
while (enumeration.hasMoreElements()) {
String element = (String) enumeration.nextElement();
System.out.println(element);
}
输出结果为:
three
two
one
从结果看Enumeration以后里面对象的顺序是原来的倒叙。
问题是这种顺序是不是恒定的。hashtable 的element是加了synchronized修饰符的,在多个客户使用时,顺序是否会发生变化?