求救! 关于java中map的用法,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/05/25 17:03:47
我定义了如下map:
final ConcurrentMap<String, User> data;

data = new ConcurrentHashMap<String, User>();

data.put("user",new User(user.getId(),user.getUsername(),user.getPassword()));

现在我想在其他的类中访问这个user并取得其中的数据.不知道可行?
怎么取?

比如A.java中有:
final ConcurrentMap<String, User> data;

你可以在B.java中,
A a = new A();

User u = a.getData().get("user");
就可以得到user的信息了。

其他类是不能访问的

但是你可以通过参数传递把这个map传过去