我的应用程序确实有很多角色。
private static HashMap<String, String> doctorcredentials = new HashMap<String, String>("doctor","Test1234!");
删除参数会引发错误。每次我只需要添加此凭据即可。不能直接定义吗?
最佳答案
HashMap 没有构造函数来支持您指定的参数。请引用documentation
要将值放入 HashMap 中,请按照下面的指定使用
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("first", "FIRST INSERTED");
hm.put("second", "SECOND INSERTED");
hm.put("third","THIRD INSERTED");
关于java - 如何在java中定义KeyPairValue中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39697452/