Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is it possible to create an Array of ArrayList?

807589Sep 25 2008 — edited Sep 25 2008
I want to create exactly 3 ArrayLists to store some Card class variables (Its for a card game).

I tried this:
private ArrayList<Card>[] hands = new ArrayList<Card>[3];
However Eclipse is showing an error saying: "Cannot create a generic array of ArrayList<Card>"

The rest of the code is beautifully simple if I can manage this...if not...ill have to keep calling differnt arraylists for different player numbers...

e.g. to add card to playerNumber = 3
public int getNumCards(int playerNumber)
{
	return hands[playerNumber].size();
}
Is simpler than multiple if/else statements to check which playerNumber was entered and then call an arraylist accordingly...

Thank You,

Cheers,
Vyder
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2008
Added on Sep 25 2008
3 comments
134 views