16.7.2 Method shuffle

Method shuffle randomly orders a List’s elements. Chapter 7 presented a card shuffling and dealing simulation that shuffled a deck of cards with a loop. Figure 16.10 uses method shuffle to shuffle a deck of Card objects that might be used in a card-game simulator.

 1   // Fig. 16.10: DeckOfCards.java 2   // Card shuffling and dealing with Collections method shuffle. 3   import java.util.List; 4   import java.util.Arrays; 5   import java.util.Collections; 6  7   // class to represent a Card in a deck of cards 8   class Card 9   {10      public static enum Face {Ace, Deuce, Three, Four, Five, Six,11         Seven, Eight, Nine, Ten, Jack, Queen, King };12      public static enum Suit {Clubs ...

Get Java™ How To Program (Early Objects), Tenth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.