I'm trying to get an array of hashmaps and here's what I have:
public class MinCuts {
HashMap<Integer, Integer> [] graph; // Graph as an array of hash maps
int size; // Number of nodes
// Empty constructor
MinCuts() {
} // END OF CONSTRUCTOR
// Reads the graph from file path as an adjacency list
public void openFile (int num_of_nodes, String path) {
In in = new In(path);
graph = (HashMap<Integer, Integer> []) new Object[num_of_nodes];
String adj_list;
for (int i = 0; i < num_of_nodes; i++) {
adj_list = in.readString();
StdOut.println(adj_list);
}
}
public static void main(String[] args) {
MinCuts x = new MinCuts();
x.openFile(10, "/Users/alekscooper/Desktop/kargerMinCut.txt");
}
I'm aware that you need to do casting when having an array like this but still it won't compile. I can't understand what the problem is. Please, help.
Thanks.