You have mixed up Java array objects and the collection framework's List
api. You can do what you want in a couple of ways:
Using arrays (highly discouraged—see this thread):
LinkedList array[] = new LinkedList[length];
...
for (int i = 0; i < array.length; ++i) {
LinkedList list = array[i];
// do stuff with list
}
Using a List
:
List<LinkedList> array = new ArrayList<LinkedList>();
...
for (Iterator<LinkedList> iter = array.iterator();
iter.hasNext();
)
{
LinkedList list = iter.next();
// do stuff with list
}
In both cases, you might benefit from using an enhanced for
loop:
for (LinkedList list : array) {
// do stuff with list
}
This works for either the array-based or List
-based versions.
P.S. You should not be using raw LinkedList
types. Instead, you should bind the generic type parameter of LinkedList
to a specific element type (even if it's Object
). For example:
List<LinkedList<String>> array = new ArrayList<LinkedList<String>>();
The language allows raw types for the sake of old code, but new code should never use them. However, the first option above will not work—you will have to use the second approach.