How to print to console a List of objects that contain fields of Enum type?

0 Deniss Diks · June 1, 2015
We have the class Card:
public class Card {

   private Rank rank;  //ENUM TYPE
   private Suit suit;  //ENUM TYPE

   public Card(Suit suit, Rank rank) {
       this.rank = rank;
       this.suit = suit;

   public Rank getRank() {
       return rank;

   public Suit getSuit() {
       return suit;

   public String toString() {
       return rank + " " + suit;

Enum Rank:
public enum Rank {

Enum Suit:
public enum Suit {

And finally the Deck class:
public class Deck {

   private List deck;

   public Deck(){

       deck = new ArrayList();

       for (Suit suit: Suit.values()){
           for (Rank rank: Rank.values()){
               Card card = new Card(suit, rank);

The question is how to make a method that will print to console the deck List?

Post a Reply


Oldest  Newest  Rating
+1 Will Moffat · June 3, 2015
I hope I'm reading this correctly.

What I would do is I would add a method to the Deck class something like: 

public void printDeck() {
   for(Card c : this.deck) {

Sorry if I misinterpreted what you're asking.
0 Deniss Diks · June 3, 2015
Thanks a lot, it works :D! Sometimes I just think too much - it's easy way to get confused.
0 Will Moffat · June 3, 2015
Haha no problem
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator