webguy08
04-11-2009, 06:09 PM
Hi all,
I have an ArrayList of type ArrayList (ArrayList<ArrayList> arrayOfAnimalArrays) which holds ArrayLists of type Animal (ArrayList<Animal> arrayOfAnimals). I also have an ArrayList of type Animal which holds all of the animals available (ArrayList<Animal> animals).
For clarity of what I'm trying to achieve, imagine this as the tale of Noah's Ark. The 'animals' ArrayList holds all of the animals Noah has to put in his Ark. The 'arrayOfAnimalArrays' ArrayList are the rooms on the Ark to hold the different animals in. The 'arrayOfAnimals' ArrayList are the animals to put in those rooms. I need to add the animals to the rooms in the Ark :p
Now back in context, I need to add an Animal from 'animals' to 'arrayOfAnimals'. I have tried the following code:
arrayOfAnimalArrays.add(0, animal.get(0));
However this does not work because of animal.get(0) where it states that it "cannot find symbol - method add(int, Animal)".
Note: I am using 0 as an example, I plan to actually use a variable (say 'i') to hold a changing value.
I guess it seems logical for it to complain because arrayOfAnimalArrays holds ArrayLists, not Animals. However, at the index 0 in arrayOfAnimalArrays there is an ArrayList of Animals, so I thought it should be able to add the animal it gets from 'animals' into it :confused:
Any ideas?
I have an ArrayList of type ArrayList (ArrayList<ArrayList> arrayOfAnimalArrays) which holds ArrayLists of type Animal (ArrayList<Animal> arrayOfAnimals). I also have an ArrayList of type Animal which holds all of the animals available (ArrayList<Animal> animals).
For clarity of what I'm trying to achieve, imagine this as the tale of Noah's Ark. The 'animals' ArrayList holds all of the animals Noah has to put in his Ark. The 'arrayOfAnimalArrays' ArrayList are the rooms on the Ark to hold the different animals in. The 'arrayOfAnimals' ArrayList are the animals to put in those rooms. I need to add the animals to the rooms in the Ark :p
Now back in context, I need to add an Animal from 'animals' to 'arrayOfAnimals'. I have tried the following code:
arrayOfAnimalArrays.add(0, animal.get(0));
However this does not work because of animal.get(0) where it states that it "cannot find symbol - method add(int, Animal)".
Note: I am using 0 as an example, I plan to actually use a variable (say 'i') to hold a changing value.
I guess it seems logical for it to complain because arrayOfAnimalArrays holds ArrayLists, not Animals. However, at the index 0 in arrayOfAnimalArrays there is an ArrayList of Animals, so I thought it should be able to add the animal it gets from 'animals' into it :confused:
Any ideas?