如何直接初始化HashMap(以字面方式)? [重复]
问题: This question already has an answer here: 这个问题已经在这里有了答案: How can I initialise a static Map? 如何初始化静态地图? 42 answers 42个答案 Is there some way of initializing a Java HashMap like this?: 有没有办法像这样初始化Java HashMap? Map<String,String> test = new HashMap<String, String>{"test":"test","test":"test"}; What would be the correct syntax? 正确的语法是什么? I have not found anything regarding this. 我还没有发现任何有关此的信息。 Is this possible? 这可能吗? I am looking for the shortest/fastest way to put some "final/static" values in a map that never change and are known in advance when creating the Map. 我正在寻找在地图中放置一些“最终/静态”值的最短/最快方法