Java:声明HashMap时使用方括号?

Java:声明HashMap时使用方括号?,java,dictionary,hashmap,square-bracket,Java,Dictionary,Hashmap,Square Bracket,我正在尝试从中改编代码,但我不明白为什么他们使用方括号声明并实例化了hashmap。下面是一些简化的示例代码: class CommunityStructure { HashMap<Modularity.Community, Float>[] nodeConnectionsWeight; HashMap<Modularity.Community, Integer>[] nodeConnectionsCount; int N; ...

我正在尝试从中改编代码,但我不明白为什么他们使用方括号声明并实例化了hashmap。下面是一些简化的示例代码:

class CommunityStructure {
    HashMap<Modularity.Community, Float>[] nodeConnectionsWeight;
    HashMap<Modularity.Community, Integer>[] nodeConnectionsCount;
    int N;
    ...

    CommunityStructure(Graph graph) {
    ...
    N = graph.getNodeCount();
    nodeConnectionsWeight = new HashMap[N];
    }
    ...
}
类社区结构{
HashMap[]节点连接权重;
HashMap[]节点连接计数;
int N;
...
社区结构(图){
...
N=graph.getNodeCount();
nodeConnectionsWeight=新哈希映射[N];
}
...
}
我以为方括号主要是指数组,所以看到它们也应用于映射时我感到困惑。

“它们”是声明
HashMap
的数组

这是完全合法的


每个数组将包含大量
HashMap
(或
Integer
作为第二个变量中的映射值)的实例

您可以创建任何
对象的数组
。在本例中,它的
HashMap
到Java,一个
Map
在任何方面都不是特别的。它只是另一种引用类型,就像
String
Integer
Socket
Random
Foo
Bar
,等等。它没有特殊的符号。明白了。以前从未见过一系列地图。谢谢它很少见,但是你会看到很多数组,比如数组映射和数组映射:-)。你应该接受答案,这样其他人就不会在同一件事上下功夫。是的,我试着点击“接受”,但它说我需要等6分钟。尴尬。