title: How can I check for duplicate values without making an array?
body: <p>I have a program that deals 20 cards based on the value of random numbers. So far it works to deal cards such as King of Spades, 2 of Hearts, etc. My job is to check whether or not the cards are duplicate using a method, but without an array. Here is my solution to checking duplicates which doesn't work for obvious reasons: </p>
  
  <pre><code>    public class Driver {
          public static void main(String [] args) {
  
              for (int i = 0; i &lt; 20; i++){
                  Cards card1 = new Cards();
                  Cards card2 = card1;
                  if (card1 == card2) {
                      card1 = new Cards(); 
                  }
                  System.out.println(card1);
              }
          }
      }
  </code></pre>
  
  <p>Here is my support class: </p>
  
  <pre><code>import java.util.Random;
  
  public class Cards {
  
      String hearts = "Hearts";
      String diamonds = "Diamonds";
      String clubs = "Clubs";
      String spades = "Spades";
  
      String suit; 
      int cardNumber; 
      String numberName; 
      String suitName;
      Random randomNum = new Random();
  
      public Cards () {
  
      }
  
      public String suit() {
          int theRandom = randomNum.nextInt(4);
  
          if (theRandom == 0 ) {           
              suitName = "hearts";
          }
          else if ( theRandom == 1) {
              suitName = "diamonds"; 
          }
          else if (theRandom == 2) {
              suitName = "clubs";
          }
          else {
              suitName = "spades";
          }
          return suitName;
      }
      public String number() {
          int theRandomNum = randomNum.nextInt(12 + 1); 
  
          if ( theRandomNum == 1 ) {
  
              numberName = "Ace";
          }
          else if ( theRandomNum == 2) {
              numberName = "2";
          }
          else if ( theRandomNum == 3) {
              numberName = "3";
          }
          else if ( theRandomNum == 4) {
              numberName = "4";
          }
          else if ( theRandomNum == 5) {
              numberName = "5";
          }
          else if ( theRandomNum == 6) {
              numberName = "6";
          }
          else if ( theRandomNum == 7) {
              numberName = "7";
          }
          else if ( theRandomNum == 8) {
              numberName = "8";
          }
          else if ( theRandomNum == 9) {
              numberName = "9";
          }
          else if ( theRandomNum == 10) {
              numberName = "10";
          }
          else if ( theRandomNum == 11) {
              numberName = "Jack";
          }
          else if ( theRandomNum == 12) {
              numberName = "Queen";
          }
          else if ( theRandomNum == 13) {
              numberName = "King";
          } 
          return numberName;
      }
  
      public String toString()
      {
          if (number() == "null") {
              return ("3" + " of " + suit());
          }
  
          return (number() + " of " + suit());
      }
  }
  </code></pre>