java - 如何在java中声明字典字典
问题描述
我有 C#.Net 代码,它调用在 JAVA Ecllips 开普勒中创建的 SOAP 服务。从 Web 服务公开的 API(函数)应将 C#.NET 代码中的数据作为参数。我需要发送到 API 的数据是 c#.NET 中的字典字典,如下所示:
Dictionary<string, Dictionary<string, string>> LinksCollection = null
;
这种结构如何在 Java 中实现?
我搜索和尝试的内容:
1]以下是在java中实现字典的方法:
1]HashMap
eg:Map<String, String> map = new HashMap<String, String>();
2]LinkedHashMap
3]Hashtable
eg: Dictionary d = new Hashtable();
Is it the right way to implement as follows ?
Declaring Dictionary:
Map<String, String> mapA = new HashMap<String, String>();
Declaring Dictionary of Dictionary:
Map<String, mapA> map = new HashMap<String, mapA>();
解决方案
添加到 Cauis Jard 的答案中,没有一种“最佳”类型可以在所有情况下使用。
如果您不关心订购,那么
HashMap
是最明显的选择。这可能是您的“默认”选择......如果线程安全不是问题。如果要保留插入顺序,请使用
LinkedHashMap
.如果要按排序顺序迭代字典键,请使用
TreeMap
.如果要从多个线程中使用字典,请根据您的要求从以下选项中进行选择:
ConcurrentHashMap
SkipListMap
Collections.synchronizedMap(...)
Collections.unmodifiableMap(...)
您还可以使用Properties
甚至是遗留/过时的Hashtable
或Dictionary
类。
推荐阅读
- apache - 404 错误文档在 .htaccess 文件中不起作用
- r - 根据基线特征从队列研究数据中删除个体
- javascript - Promise JavaScript 代码解释中的延迟函数
- python-3.x - 在 tensorflow api 对象检测模型中检测微小对象
- java - StackTraceElement 数组的哈希码每次返回不同的值
- c# - 为什么当前文本没有更新?
- python - 在python中下载文件时如何制作进度条
- informatica-powercenter - 将 oracle 表值转换为 PDF 或 TXT
- javascript - 路由器推送有时会在 url 路径中推送 [object Object]
- node.js - 我想获得观看次数+点赞次数最多的 20 条记录,在 mongoose 中我该怎么做?