我正在努力将 C# 程序转换为 Java 程序。 Java 中是否有一个类在用法上可与 C# 类相媲美
Dictionary<key, value> dictionary = new Dictionary<key, value>();
请您参考如下方法:
有一个Dictionary Java 中的抽象类,它有一个直接子类 - Hashtable .
但是在javadoc中明确的说:
This class is obsolete. New implementations should implement the Map interface, rather than extending this class.
示例 map :
Map<Key, Value> map = new HashMap<Key,Value>();
请注意 Map是一个接口(interface),HashMap是 Map 的一个实现。还有许多其他 Map 实现,例如 LinkedHashMap , IdentityHashMap等。使用哪种实现取决于您的需要。
