java - Hashmap 在 HashMap 中尝试插入一些东西

标签 java hashmap

这是我的 HashMap :

protected HashMap<String, HashMap<String, Player>> prisonsPlayers = new HashMap<String, HashMap<String, Player>>();

我尝试在其中插入一些内容:

prisonsPlayers.put(player.getWorld(), (HashMap<player.getName(), player>));

我得到的错误:

Multiple markers at this line
    - Syntax error, insert ")" to complete 
     Expression
    - Syntax error on token ")", invalid 
     Expression

我知道我做错了什么,但无论我如何尝试,无论我做什么,我都不知道如何将该数据插入到我的 HashMap 中。

最佳答案

这一行

prisonsPlayers.put(player.getWorld(), (HashMap<player.getName(), player>));

应该是这样的

Map<String, Player> map  = new HashMap<String, Player>();
map.put(player.getName(),player);  
prisonsPlayers.put(player.getWorld(), map);

关于java - Hashmap 在 HashMap 中尝试插入一些东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20685173/

相关文章:

java - 为 TypedQuery 指定的类型与其自身不兼容

java - 当 Redis 连接出现问题时,在 Hibernate 中熔断 L2 缓存

c++ - HashMap 元素的值未正确打印

java - 从文本文件中获取单行和多行值

java - Arraylist 值未出现在 HashMap 中

java - 如何使用JCheckBoxes selection for use?

java - 我无法在java中将文本文件设置为只读模式

java - 如何修复 Java :26: error: No suitable constructor found

java - 显示 HashMap 时出现问题

c++ - 在 C++ 中实现 Hashmap::模板化数据类型的散列函数