I have an implemented data structure called List (it's a singly linked list). I have the following code in my Java program:
List[] Adjacent = new List[N]; // Trying to create an array of N List objects
Suppose N = 6. I want Adjacent to be an array of six elements where each one of them is a List object itself. But when I try to access it, the array is actually an array of N null references. What is going on?
Of course I did the following to solve my problem:
for (int p = 0; p < N; p++)
Adjacent[p] = new List();
But that's not what I really want. Is there a more efficient/nice way to do it?
List. It is the name of a widely used interface...