这是我创建的地图中的地图
private static Map<Integer, Map<String, String>> directory = new HashMap<>();
Run Code Online (Sandbox Code Playgroud)
我想知道如何使用上面的put()方法.
我试过这个例子:
directory.put(5,"Test1","Test2");
Run Code Online (Sandbox Code Playgroud)
但这不正确.我通过eclipse得到以下消息:
The method put(Integer, Map<String,String>) in the type Map<Integer,Map<String,String>> is not applicable for the arguments (int, String, String)
Run Code Online (Sandbox Code Playgroud)
但我必须坚持大学的指导方针.有一个JUnitTest,还有put方法.看看他们是怎么做到的:
addEntry(1, "Name", "Dall", "FirstName", "Karl", "phoneNr", "4711");
Run Code Online (Sandbox Code Playgroud)
这就是我在大学里的addEntry方法
public static void addEntry(int nrP, String... attrValPairs) throws IllegalArgumentException
Run Code Online (Sandbox Code Playgroud)
你的是嵌套的Map,所以你需要Map在外部的值中有一个对象Map:
if(!directory.containsKey(5)) {
directory.put(5, new HashMap<>());
}
directory.get(5).put("Test1", "Test2");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
821 次 |
| 最近记录: |