I have a class named Card and I have this for loop:
int i;
for (i = 0; i < 13; i++) {
Card cardNameHere = new Card();
}
What I want to do is create new instances based on the for loop. So for example, I would like the names to be card1, card2, card3, etc. The number would come from the for loop.
I have tried this and it does not seem to work:
int i;
for (i = 0; i < 13; i++) {
Card card[i] = new Card();
}
Can anyone tell me what I am doing wrong?
Thanks.
So I am using the solution from Hovercraft Full Of Eels, but I have another problem.
I am using cardList.add(new Card()); , and when I try to use Card(i) to set the name, java won't let me do it. Using it without i works fine, but how do I access it so I can call another method on it such as setId. I would like to call cardName.setId();