import java.util.*; public class ListOfLists { public static void main (String[] argv) { // The method makeListOfLists() will return the list of lists. LinkedList> listOfLists = makeListOfLists (); // We'll print each list on a separate line. // Note the use of the new for-loop. int count = 0; for (LinkedList strList: listOfLists) { // Each strList is a string-list, a list of strings. System.out.print ("Contents of list# " + count + ": "); // Print all the strings in strList. for (String s: strList) { System.out.print (" " + s); } System.out.println (); count ++; } } static LinkedList> makeListOfLists () { // First, we'll make three linked lists containing String's. LinkedList classics = new LinkedList(); classics.add ("Citizen Kane"); classics.add ("Casablanca"); classics.add ("The Godfather"); LinkedList kids = new LinkedList(); kids.add ("Bambi"); kids.add ("Snow White"); kids.add ("Lion King"); kids.add ("Toy Story"); LinkedList sciFi = new LinkedList(); sciFi.add ("2001: A Space Odyssey"); sciFi.add ("Star Wars"); sciFi.add ("Jurassic Park"); // Create an instance of the list that will contain the others. LinkedList> listOfLists = new LinkedList>(); // Now add each list to this list. Since a list can store // any kind of object, and a list is an object, we can store lists in a list. listOfLists.add (classics); listOfLists.add (kids); listOfLists.add (sciFi); return listOfLists; } }