Java 中 .NET SortedDictionary 的等价物是什么?
如果 .NET 有一个 SortedDictionary 对象...这在 Java 中是什么, 请?我还需要能够在 Java 代码中检索(元素的)Enumeration
..这样我就可以迭代所有键。
我认为这是一个 TreeMap ?但我不认为有一个暴露的 Enumeration
?
有什么想法吗?
If .NET has a SortedDictionary object ... what is this in Java, please? I also need to be able to retrieve an Enumeration
(of elements), in the Java code .. so I can just iterate over all the keys.
I'm thinking it's a TreeMap ? But I don't think that has an Enumeration
that is exposed?
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TreeMap
将是正确的选择。至于所有键(或值)的集合,任何Map
都会公开keySet()
和values()
。编辑(用代码标签回答您的问题)。假设您有一个
Map
:您还可以使用
entrySet()
而不是keySet()
或values( )
以便迭代键->值对。TreeMap
would be the right choice. As for the Collection of all the keys (or values), anyMap
exposeskeySet()
andvalues()
.EDIT (to answer your question with code tags). Assuming you have a
Map<String, Object>
:You can also use
entrySet()
instead ofkeySet()
orvalues()
in order to iterate through the key->value pairs.TreeMap
可能是您能找到的最接近的东西。您可以通过调用
TreeMap.keySet();
并迭代返回的 Set 来迭代键:这相当于:
You could also try the following:
这相当于以下 .NET 代码:
TreeMap
is probably the closest thing you're going to find.You can iterate over the keys by calling
TreeMap.keySet();
and iterating over the Set that is returned:It would be the equivalent of:
You could also try the following:
Which is the equivalent to the following .NET code:
您需要的是 entrySet() SortedMap(TreeMap)的方法。
What you need is entrySet() method of SortedMap (TreeMap).