dcsimg

How do you create a multi-dimensional List?

John Zukowski

Since the elements of a List are objects, in order to make the List multi-dimensional, each object in the outer list needs to be a List, too. For instance, ...


List list = new ArrayList(10);
for (int i=0; i<10; i++) {
  list.set(i, new LinkedList());
}
Then just fill up each inner list with items.