.Net Hashtable、Java Hashtable和HashMap之间的区别

时间:2021-01-18 17:18:03

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?

我说。net Hashtable不是同步的,而Java Hashtable是同步的,这是对的吗?与此同时,Java HashMap没有同步,性能更好吗?

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.

我正在重写一个Java应用程序,它在c#中大量使用hashmap,我希望使用散列表,并确保性能基本相同。

2 个解决方案

#1


6  

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.

我认为您所要问的是,Java中的hashmap和c#中的HashTables是否大致相同,从性能的角度来看,基本上是正确的。我记得HashMaps不会抱怨如果你插入重复的键,而c#中的HashTable会。

#2


0  

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

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

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

#1


6  

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.

我认为您所要问的是,Java中的hashmap和c#中的HashTables是否大致相同,从性能的角度来看,基本上是正确的。我记得HashMaps不会抱怨如果你插入重复的键,而c#中的HashTable会。

#2


0  

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

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

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