For a programming class I am creating a blackjack program for the first homework assignment. The professor has given us a sample Card class, which includes the method to add them to a deck. For her deck, she uses an ArrayList, which you can easily Knuth Shuffle with the Collections.shuffle() method.
That method does not work for Stacks though (obviously), but I think a Stack structure would work best for this program because you may pop and push cards into and out of the deck.
Both java.util.ArrayList<E>
and java.util.stack<E>
implement the java.util.List<E>
interface, and Collections.shuffle()
takes a java.util.List<?>
as a parameter. You should be able to pass a Stack
into Collections.shuffle()
, unless you're using a different stack implementation that does not implement java.util.list<E>
. If you are, I would advise you to switch to a different stack implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With