CountCet
CountCet

Reputation: 4573

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.

Upvotes: 5

Views: 4882

Answers (2)

Noah Heldman
Noah Heldman

Reputation: 6874

By default, .NET Hashtables are not synchronized, but you can create a synchronized wrapper around one, like so:

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

Upvotes: 0

Jon
Jon

Reputation: 2085

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.

Upvotes: 6

Related Questions