English 中文(简体)
替换陈旧 Java学班
原标题:Replacement for obsolete Hashtable class in Java
  • 时间:2011-11-22 06:59:50
  •  标签:
  • java

When I tried to use the hashtable class, Netbeans gave me an error saying:

这些班级虽然仍然得到支持,但被JDK1.2收集班所淘汰,可能不应用于新的发展。

However, I can t seem to find an example online on a better replacement for Hashtable. Any suggestions?

最佳回答
问题回答

你可能使用哈希姆地图:

Map<String, Integer> mymap = new HashMap<String, Integer>();

There are cases when a method outside your control requires an Hashtable. Java s own javax.management.ObjectName is such an example[1].

When the external interface requires it you have to use Hashtable. In netbeans, you can use:

@SupresssWarnings("UseOfObsoleteCollectionType")

在当地镇压警告。

See See See

1: I wonder why they used Hashtable and not HashMap, since ObjectName is available since 1.5 and Hashtable is obsolete since 1.2

<<>Summary

最近的更换是Hasmaap(通常是通过地图接口)。


但注意到,哈希姆普省的情况并非如此。 www.un.org/Depts/DGACM/index_spanish.htm 在大多数情况下,这不是的问题,而是有意使大多数 Java收集工作变得不易安全,以避免对大多数常见情况处以罚款。 但是,如果你依靠哈希姆的翻新安全,现在需要替代,也应当翻新,那么你有两种选择:

  • If you need a simple synchronization wrapper for an existing Map - use Collections.synchronizedMap(...)
  • If you need a class carefully and optimally designed for concurrent access - use ConcurrentHashMap (usually via the ConcurrentMap interface that extends the Map interface with additional concurrency features).




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...