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>andjava.util.stack<E>implement thejava.util.List<E>interface, andCollections.shuffle()takes ajava.util.List<?>as a parameter. You should be able to pass aStackintoCollections.shuffle(), unless you’re using a different stack implementation that does not implementjava.util.list<E>. If you are, I would advise you to switch to a different stack implementation.