java - iterate through all combinations of cards -
i'm creating card game , iterate through possible combinations of card.
for example (ace of hearts, 2 of hearts), (ace of hearts, 2 of spades), (ace of hearts, 2 of clubs).... etc
i'm doing in java
currently have this:
to start have
list<card> deckofcards = new arraylist<card>();
which deck containing cards. create
queue<card> deckofcardswithoutduplicates = new linkedlist<card>(); deckofcardswithoutduplicates = deckofcards;
now want iterate through of cards without duplicates.
(card c : deckofcards) { deckofcardswithoutduplicates.remove(c); (card c1 : deckofcardswithoutduplicates) { //something here irrelevant } deckofcardswithoutduplicates.add(c); }
however java.util.concurrentmodificationexception
. can give me hints on how better?
it's because you're trying remove list you're looping through.
to remove list you're looping through, need use iterator
Comments
Post a Comment