Working with arrays of lists pattern in java

Posted by Mad Wombat on Stack Overflow See other posts from Stack Overflow or by Mad Wombat
Published on 2010-03-26T04:27:13Z Indexed on 2010/03/26 4:33 UTC
Read the original article Hit count: 341

Filed under:

I am writing a card game in java where I need to spread cards from a deck into several columns until I have fixed amount of cards left. This is how I do this.

public class Column extends ArrayList {}
List deck = Cards.createNewDeck();
Column[] columns = new Column[10];
int c = 0;

while (deck.size() > 50) {
    if (c == 10) {
        c = 0;
    }
    if (columns[c] == null) {
        columns[c] = new Column();
    }
    columns[c].add(Cards.dealTopCard(deck));
    c += 1;
}

This somehow seems clunky. Is there a more readable/comprehensive way of doing the same thing?

© Stack Overflow or respective owner

Related posts about java