-1

I'm trying to adapt code from here and I can't figure out why they've declared and instantiated their HashMaps using square brackets. Here's some simplified sample code:

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

    CommunityStructure(Graph graph) {
    ...
    N = graph.getNodeCount();
    nodeConnectionsWeight = new HashMap[N];
    }
    ...
}

I thought square brackets were mainly meant for arrays, so I was confused to see them applied to Maps as well.

istewart
  • 437
  • 5
  • 18

1 Answers1

2

"They" are declaring arrays of HashMaps.

This is perfectly legit.

Each array will contain a number of instances of HashMap<Modularity.Community, Float> (or Integer as map value in the second variable).

Mena
  • 47,782
  • 11
  • 87
  • 106
  • Got it. Never seen an array of Maps before. Thanks! – istewart Mar 30 '15 at 16:11
  • its rare however you will be seeing lot of arrays like array of map and map of array :-). you should accept the answer so other person don't put effort in same thing. – Panther Mar 30 '15 at 16:13
  • Yeah I've tried to hit "accept" but it says I need to wait 6 minutes. Awkward. – istewart Mar 30 '15 at 16:15