I've created an array of LinkedList of Connection
objects using the second answer from here. That is, I've done:
LinkedList<Connection>[] map = (LinkedList<Connection>[]) new LinkedList[count];
However, I am confused as to how to access each element of the array (ie each LinkedList) and create a new node. Right now, I have:
for (int j = 0; j < numOfConnections; j++) {
map[j].add(new Connection(s.next(), s.nextDouble(), s.next()));
}
But I think this would only add a single new node to each LinkedList element of the Array. I want to loop through and add numOfConnections
amount of nodes to each LinkedList element. For example, 3 nodes in map[0]
, 5 nodes in map[1]
, 2 nodes in map[2]
, etc.