在java中创建一个二维的hashmap数组。

时间:2022-01-12 02:21:20

I would like to create a 3 dimensional array in java where the first two dimensions are indices (0-100) and (0-4) and the 3rd dimension is a dictionary index (12, 18, 22, 49, etc)

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

How can I set this up? I thought:

我该如何设置呢?我想:

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

But I am getting errors. Am I approaching this correctly?

但我有错误。我的理解正确吗?

Thanks!

谢谢!

1 个解决方案

#1


1  

Why not use a class to wrap the HashMap?

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

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


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

#1


1  

Why not use a class to wrap the HashMap?

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

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


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