Joanne Neal wrote:Have you been told to use a list of lists ?
The better solution is to create a Company class and an Employee class and the Company class will contain a list of Employees.
Off topic - your list of employees reminds me of a Monty Python sketch.
Campbell Ritchie wrote:You ought to have declared it as Rob told you. You can iterate a List<List<Foo>> in a for-each loop, with each element found being a List<Foo>. Like this:
Rob Spoor wrote:Collections can hold any objects, and that includes other collections. At least if you use the right generic type:
Campbell Ritchie wrote:There is no such thing as a multidimensional array, only an array of arrays. There is no such thing as a multidimensional ArrayList, but you can have a List of Lists.
Paul Clapham wrote:
Vladimir Korabelnikoff wrote:Or, would I be better off creating a new array (and copying the other array to the new one) every time I add an element to it?
But that's basically what an ArrayList does. So if that's what you need then use an ArrayList.
Bear Bibeault wrote:Well, List is an interface, so you cannot create an instance of it. In fact, ArrayList is one of the container classes that implements List. What you need to do is to look through the collection classes that implement List and choose the one that best meets your requirements.
Welcome to the Ranch.