在java中动态创建嵌套哈希Map的名称

yhqotfr8  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(223)

问题:
java新手,尝试动态填充嵌套hashmap的名称,我应该如何修改第10行
使结果与下面的结果一致,以便在嵌套的hashmap上执行操作;
或者名字不重要?
预期结果:

Node(A, tempA)
Node(B, tempB)
...
Node(Z, tempZ)

代码:

Note that there are blocks of code excluded in the middle, so to focus on the approach for the question above.

1  private Map<String, HashMap<String, Integer>> nodes = new HashMap<>();
2 
3  String [] letters = new String[26];
4      for (int i = 0; i <26; i++){
5          char temp = (char) (65 + i);
6          letters[i] = String.valueOf(temp);
7      }
8
9  for (int i = 0; i < 26; i++){
10    HashMap<String, Integer> tempA = new HashMap<>();
11    nodes.put(letters[i], tempA);
12 }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题