I have made this array of cards using enumerators for the suit and rank, but it is immutable. I cannot remove anything from the Deck
. I can use shuffle
by using
void shuffle() {
List<Card> shuffold = Arrays.asList(cards);
}
I cannot use remove
to deal cards even when using Arrays.asList(cards)
I don't want to use a new deck every time I deal a card only when starting a new hand. Should I make the Deck
an ArrayList
or can I somehow convert it to a mutable set or is that even possible?
public class Deck {
public final Card[] cards;
public Deck() {
cards = new Card[52];
int i = 0;
for (Suit suit : Suit.values()) {
for (Rank rank : Rank.values()) {
cards[i++] = new Card(rank, suit);
}
}
}
}
I can already use shuffle
but the array is still immutable in that I cannot use this to remove the first card in the deck:
void deal() {
Collection deal = new ArrayList(Arrays.asList(cards));
deal.remove(0);
}