Inward Jim
Inward Jim

Reputation: 47

Adding objects to an arraylist inside another arraylist

I'm sorry about how vague this is, but there's just too much code to put up.

It's a game of Five Card Stud. Basically I'm attempting to add objects to an arraylist inside of another arraylist.

Here's where I create the players array and add an array from the Hand class to it, at least I think that's what's happening:

players = new ArrayList<Hand>();
for(int index = 0; index < playerCount; index++)
{
    players.add(new Hand());
}

Later I attempt to add cards to the Hand array within the players array in a circular deal. As there are five cards, the first loop goes five times. The second goes for the length of the players array (the total number of players) and should add a single card each time.

for(int dealt = 0; dealt <= 5; dealt++)
{
    for(int index = 0; index <= players.size(); index++)
    {
        //what goes here????
    }
}

There is a deal method in the Deck class initialized by:

myDeck = new Deck();

....but I'm not sure how to apply it to the 'sub-array.'

This is a tall order I feel, so thanks in advance!

Upvotes: 0

Views: 1168

Answers (1)

Jeroen Vannevel
Jeroen Vannevel

Reputation: 44439

for(int dealt = 0; dealt <= 5; dealt++)
{
    for(int index = 0; index <= players.size(); index++)
    {
        players.get(index).addCard();
    }
}

Does the addCard method take any parameters?

Right now every player will get 5 cards.

Upvotes: 1

Related Questions