简体   繁体   中英

Differences between .Net Hashtable, Java Hashtable & HashMap

Am I correct in saying that a .Net Hashtable is not synchronized while a Java Hashtable is? And at the same time a Java HashMap is not synchronized and has better performance?

I am rewriting a Java app that makes heavy use of HashMaps in C# and I would like to use a HashTable and ensure that the performance is basically equivalent.

I think what you're asking is if HashMaps in Java and HashTables in C# act in roughly the same way and you're largely correct from a performance point of view. HashMaps as I recall do not complain if you insert duplicate keys whereas HashTable in C# will.

默认情况下,.NET哈希表不同步,但是您可以围绕一个哈希表创建一个同步包装器,如下所示:

Hashtable myHash = Hashtable.Synchronized(new Hashtable());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM