title: I dont understand why length of foundCards is being reset back to 0 evey time i tried to check if selected 3 cards is a set or not
body: <pre><code>import java.util.ArrayList;
  
  /**
   * This class is used to create card object
   * @author Suman
   *
   */
  public class Cards {
  
          private String num;
          private String pattern;
          private String color;
          private String shape;
  
          public ArrayList&lt;ArrayList&lt;String&gt;&gt; foundCards = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
  
          //constructors
          public Cards(String num, String pattern, String color, String shape){
              this.num=num;
              this.pattern=pattern;
              this .color=color;
              this.shape=shape;
          }
  
          /**
           * get methods
           * @return number of card
           */
          public String getNum(){
              return num;
          }
  
          /**
           * get methods
           * @return pattern of card
           */
          public String getPattern(){
              return pattern;
          }
  
          /**
           * get methods
           * @return color of card
           */
          public String getcolor(){
              return color;
          }
  
          /**
           * get methods
           * @return shape of card
           */
          public String getShape(){
              return shape;
          }
  
          /**
           * set method that sets number of card
           * @param num number of card
           */
          public void setNum(String num){
              this.num=num;
          }
  
          /**
           * set method that sets pattern of card
           * @param pattern pattern of card
           */
          public void setPattern(String pattern){
              this.pattern=pattern;
          }
  
          /**
           * set method that sets color of card
           * @param num color of card
           */
          public void setColor(String color){
              this.color=color;
          }
  
          /**
           * set method that sets shape of card
           * @param num shape of card
           */
          public void setShape(String shape){
              this.shape=shape;
          }
  
  
          /**
           * checks if the selected set of cards is valid or not
           * @param card1 is first card picked by player
           * @param card2 is second card picked by player
           * @param card3 is third card picked by player
           * @return true if given set of three cards have all same or all different property
           */
  
          public boolean CheckSet(Cards card1, Cards card2, Cards card3) {
  
              boolean isset = false;
              int matchingNoOfProperty=0;
  
              String checkcard1 = card1.getNum()+card1.getPattern()+card1.getcolor()+card1.getShape();
              String checkcard2 = card2.getNum()+card2.getPattern()+card2.getcolor()+card2.getShape();
              String checkcard3 = card3.getNum()+card3.getPattern()+card3.getcolor()+card3.getShape();
  
              //checking if user entered same card multiple times
              if (checkcard1.equals(checkcard2)){
                  System.out.println("You cannot enter same card multiple times");
                  return isset;
              }
              //checking if selected 3 cards has all same property or all different property
              // if all card has all same or all different property then increase matchingNoOfProporty by 1
              if ((card1.getNum().equals(card2.getNum()) &amp;&amp; card1.getNum().equals(card3.getNum()) &amp;&amp; card2.getNum().equals(card3.getNum())) || (!card1.getNum().equals(card2.getNum()) &amp;&amp; !card1.getNum().equals(card3.getNum()) &amp;&amp; !card2.getNum().equals(card3.getNum()))){
                      matchingNoOfProperty++;   
              }
              if ((card1.getcolor().equals(card2.getcolor()) &amp;&amp; card1.getcolor().equals(card3.getcolor()) &amp;&amp; card2.getcolor().equals(card3.getcolor())) || (!card1.getcolor().equals(card2.getcolor()) &amp;&amp; !card1.getcolor().equals(card3.getcolor()) &amp;&amp; !card2.getcolor().equals(card3.getcolor()))){
                  matchingNoOfProperty++;   
              }
              if ((card1.getPattern().equals(card2.getPattern()) &amp;&amp; card1.getPattern().equals(card3.getPattern()) &amp;&amp; card2.getPattern().equals(card3.getPattern())) || (!card1.getPattern().equals(card2.getPattern()) &amp;&amp; !card1.getPattern().equals(card3.getPattern()) &amp;&amp; !card2.getPattern().equals(card3.getPattern()))){
                  matchingNoOfProperty++;   
              }
              if ((card1.getShape().equals(card2.getShape()) &amp;&amp; card1.getShape().equals(card3.getShape()) &amp;&amp; card2.getShape().equals(card3.getShape())) || (!card1.getShape().equals(card2.getShape()) &amp;&amp; !card1.getShape().equals(card3.getShape()) &amp;&amp; !card2.getShape().equals(card3.getShape()))){
                  matchingNoOfProperty++;   
              }
  
              //if all four property are same or different then set isset to true
              if (matchingNoOfProperty==4){
                  isset=checkRepeat(checkcard1,checkcard2,checkcard3);
              }
              return isset;
          }   
  
  
          public boolean checkRepeat(String checkcard1, String checkcard2, String checkcard3){
              System.out.println("I'm inside check repeat");
              ArrayList&lt;String&gt; tempcards = new ArrayList&lt;String&gt;();
  
              boolean validSet = true;
              String card1 = checkcard1;
              String card2 = checkcard2;
              String card3 = checkcard3;
              if (foundCards.size()==0){
                  System.out.println("I'm inside check repeat if");
                  tempcards.add(card1);
                  tempcards.add(card2);
                  tempcards.add(card3);
                  foundCards.add(tempcards);
                  System.out.println("size of foundcards" + foundCards.size());
              }
              else {
                  System.out.println("I'm inside check repeat else");
                  for (int i=0 ; i&lt;foundCards.size() ; i++){
                      int cardMatch =0 ;
                      for (int j=0; j &lt;3 ; j++){
                          System.out.println("found card: " + foundCards.get(i).get(j));
                          System.out.println("cards to check1: " + card1);
                          System.out.println("cards to check2: " + card2);
                          System.out.println("cards to check3: " + card3);
                          if (foundCards.get(i).get(j).equals(card1) || foundCards.get(i).get(j).equals(card2) || foundCards.get(i).get(j).equals(card3)){
                              cardMatch++;
                          }
                      }
                      if (cardMatch ==3){
                          validSet =false;
                          break;
                      }
                  }
              }
              return validSet;
  
          }
  }
  </code></pre>
  
  <p>I am trying to make a text version of set game. So what it is doing here is user enters 3 cards. Then I call checkSet method to see if these 3 cards form a set or not. With checkRepeat I'm trying to find out if entered set of cards has been found already by user or not. But every time checkRepeat is called it sets length of foundCards to 1 after storing 3 sets of card in it. But when I call it again to check for sets it returns 1 again. its never going inside else part. I don't know if its because my cards class is being called again, so that its resetting foundcards to 0. Is there a way to solve this issue</p>
  
  <p>below is loop part of my main method</p>
  
  <pre><code>   public void displayCards(Cards[] cards) {
      //creating 3 empty cards
      Cards playCard1= new Cards("","","","");
      Cards playCard2= new Cards("","","","");
      Cards playCard3= new Cards("","","","");
  
      boolean isSet = false;
      boolean loop = true;
      Scanner scan = new Scanner(System.in);
  
           while (loop){
          System.out.println("\n");
  
          //displaying 12 cards on board
          board.toString(cards);
  
          System.out.println("\nTotal no of possible sets in this 12 set cards : " + possibleNumOfSet);
          System.out.println("Total no of sets you have found : " + setsFound);
          System.out.println("\nPlease enter a group of three cards as displayed");
  
          //first card
          System.out.print("Please enter first card : ");
          String card1 = scan.nextLine();
          if (card1.equalsIgnoreCase("quit")){    //stop the program
              System.out.println("\n THANK YOU for playing");
              System.exit(0);
          }
          String[] splitCard1 = validateCard(card1,cards);
          playCard1 = new Cards(splitCard1[0],splitCard1[1],splitCard1[2],splitCard1[3]);
  
          //second card
          System.out.print("Please enter second card : ");
          String card2 = scan.nextLine();
          if (card2.equalsIgnoreCase("quit")){    //stop the program
              System.out.println("\n THANK YOU for playing");
              System.exit(0);
          }
          String[] splitCard2 = validateCard(card2,cards);
          playCard2 = new Cards(splitCard2[0],splitCard2[1],splitCard2[2],splitCard2[3]);
  
          //third card
          System.out.print("Please enter third card : ");
          String card3 = scan.nextLine();
          if (card3.equalsIgnoreCase("quit")){    //stop the program
              System.out.println("\n THANK YOU for playing");
              System.exit(0);
          }
          String[] splitCard3 = validateCard(card3,cards);
          playCard3 = new Cards(splitCard3[0],splitCard3[1],splitCard3[2],splitCard3[3]);
  
  
          //calling checkSet function to check if chosen 3 cards is a set
          isSet = playCard1.CheckSet(playCard1, playCard2, playCard3);
  
  
          // if chosen 3 cards is a set then display congratulations message and increase value of setsFound by 1.
          if (isSet){
              System.out.print("\nCongratulations! You have found a set.\n\n");
              System.out.println("Your answer:");
              System.out.println("\t"+card1 + "    "+ card2 + "    "+ card3);
              System.out.println("Hit Enter to continue.");
              scan.nextLine();
              setsFound++;
          }
          else {
              System.out.println("\nWhoops.....  This is not a set");
              System.out.println("Hit Enter to continue.");
              scan.nextLine();
          }
  
          //if user finds all possible number of sets it will break the loop and display congratulations message.
          if (setsFound == possibleNumOfSet){
              gameFinish();
              break;
          }
      }
  </code></pre>
  
  <p>}</p>