0.线程安全
1)线程安全Hashtable
2)线程不安全ConcurrentHashMap,LinkedHashTreeMap,TreeMap,HashMap
1.建议遍历方法
//方法1)
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
String value = map.get(key);
// System.out.println(key + "\t" +value);
}
//方法2)
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Iterator<Map.Entry<String, String>> sIterator = entrySet.iterator();
while (sIterator.hasNext())
{
Map.Entry<String, String> entry = sIterator.next();
String key = (String) entry.getKey();
String value = map.get(key);
// System.out.println(entry.getKey() + "\t" + entry.getValue());
}
这两种效率都差不多
网友评论