开发者

How to iterate a synchronized treeMap?

Currently have this implementation:

static Map s_AvailableGameTables = Collections.synchronizedMap(new TreeMap<Integer,Table>());   

How开发者_StackOverflow社区 can I iterate over all it's content from the start to the end like an array?

Thanks


Assuming the declaration is

static Map<Integer,Table> s_AvailableGameTables = Collections.synchronizedMap(new TreeMap<Integer,Table>());

(not just Map)

The following will iterate over all key/value pairs:

for (Map.Entry<Integer,Table> e : s_AvailableGameTables.entrySet())
{
    int key = e.getKey();
    Table tbl = e.getValue();
}


If you want to iterate over the entries (key-value pairs in the map):

for (Map.Entry<Integer, Table> entry : s_AvailableGameTables.entrySet()) {
    System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜