简体   繁体   English

如何使用 TreeMap java?

[英]How do I use TreeMap java?

I have been writing this line:我一直在写这一行:

Map s_AvailableGameTables = Collection.synchronizedMap(new TreeMap());

And got the following error: cannot find symbol并得到以下错误:找不到符号
symbol: method synchronizedMap(java.util.TreeMap) location: interface java.util.Collection符号:方法 synchronizedMap(java.util.TreeMap) 位置:接口 java.util.Collection

Although I wrote虽然我写了

import java.util.*;
import java.util.TreeMap;
import java.util.Collections;
import java.util.Map;  

What is the reason for that?这是什么原因?
Thanks谢谢

It's a simple typo.这是一个简单的错字。 It should be Collections , not Collection .它应该是Collections ,而不是Collection


Try,尝试,

Map s_AvailableGameTables = Collections.synchronizedMap(new TreeMap());

A synchronized TreeMap is rather slow.同步的 TreeMap 相当慢。 It's probably better to use ConcurrentSkipListMap if you want a navigatable map that supports concurrency.如果您想要一个支持并发的可导航 map,使用ConcurrentSkipListMap可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM