I have tried to find an answer to my question here but with no luck - please let me know if this was already answered and I will delete this question.
I want to iterate through an ArrayList of playing cards, here is my code:
public static void showCards(ArrayList<Card> cards){
Iterator iterator = cards.iterator();
while(iterator.hasNext()){
String object = String.valueOf(iterator.next());
System.out.println(object);
}
}
I want to print the value of each card, but I am only getting the reference:
com.company.Card@4517d9a3
com.company.Card@4517d9a3
I have tried looping through as well - same thing. What am I doing wrong?
Card class if needed:
public class Card {
private CardSuit cardSuit;
private CardValue cardValue;
public Card(CardSuit cardSuit, CardValue cardValue) {
this.cardValue = cardValue;
this.cardSuit = cardSuit;
}
public CardValue getCardValue() {
return cardValue;
}
public CardSuit getCardSuit() {
return cardSuit;
}
}