【问题标题】:create a 2 dimensional array of HashMaps in java在java中创建一个二维的HashMaps数组
【发布时间】:2016-01-08 17:54:06
【问题描述】:

我想在 java 中创建一个 3 维数组,其中前两个维度是索引 (0-100) 和 (0-4),第三维是字典索引 (12、18、22、49 等)

我该如何设置?我想:

    HashMap<Integer, Integer>[][] mem;
    mem = new HashMap<Integer, Integer>[101][5];

但我遇到了错误。我的处理方法正确吗?

谢谢!

【问题讨论】:

  • 只需删除末尾的(),因为您正在制作一个数组。
  • 您不能创建通用数组。混合使用数组和泛型并不是一个好主意。
  • 谢谢 Paul - 你知道我应该如何构建这样的数组吗?
  • 感谢 alfasin - 是的,如果有可行的方法,我会尝试一种新方法。
  • 不就是int[][][]吗?

标签: java arrays dictionary multidimensional-array hashmap


【解决方案1】:

为什么不使用类来包装 HashMap?

class Dictionary {
    HashMap<Integer, Integer> map = new HashMap<>();
}


Dictionary[][] mem = new Dictionary[101][5];

【讨论】:

    猜你喜欢
    • 2021-03-16
    • 1970-01-01
    • 2016-04-23
    • 2020-08-02
    • 2013-07-16
    • 2020-04-21
    • 2016-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多