在Java中,与.NET SortedDictionary等价的是什么?

What's the equivalent to a .NET SortedDictionary, in Java?

如果.NET有SortedDictionary对象…请问这是什么在爪哇?我还需要能够在Java代码中检索EDCOX1的0个元素(元素)。所以我可以迭代所有的键。

我想这是一个Treemap?但我不认为有一个暴露的Enumeration

有什么想法吗?


TreeMap会好的正确的选择。As for the collection of the keys(或在任何Mapvalues),exposes values()keySet()布尔。P></

编辑(你的问题和答案的代码标签)。assuming Map:You have aP></

1
2
3
4
for (String key : map.keySet()) {
     System.out.println(key); // prints the key
     System.out.println( map.get(key) ); // prints the value
}

使用entrySet()instead of You can also values()keySet()or the key to在一阶迭代→θ值。P></


TreeMapis probably the thing to find closest你去。P></

你可以打电话TreeMap.keySet();over the keys的迭代和迭代模式集:that is over the returnedP></

1
2
3
4
5
// assume a TreeMap<String, String> called treeMap
for(String key : treeMap.keySet())
{
    string value = treeMap[key];
}

它会好:当量of theP></

1
2
3
4
5
// assume a SortedDictionary called sortedDictionary
foreach(var key in sortedDictionary.Keys)
{
    var value = sortedDictionary[key];
}


HR></你也可以尝试下面:P></

1
2
3
4
5
6
// assume TreeMap<String, String> called treeMap
for (Map.Entry<String, String> entry : treeMap.entrySet())
{
    String key = entry.getKey();
    String value = entry.getValue();
}

which is the to the following出现代码等价:P></

1
2
3
4
5
6
// assume SortedDictionary<string, string> called sortedDictionary
foreach(KeyValuePair<string, string> kvp in sortedDictionary)
{
    var key = kvp.Key;
    var value = kvp.Value;
}


是你需要的是()entryset method of sortedmap(treemap)。P></