title: Empty all array values except two values
body: <p>I'm currently developing Yahtzee game in java and I got stuck with the re-roll dice logic.</p>
  
  <p>I have an array with the 5 random dice, the player can decide which die he wants to keep and the other dice to re-roll. </p>
  
  <p>For example, the player decided to keep the die with side 4 and the die with side 3. What I'm doing is creating a new array and storing only the selected dice.</p>
  
  <pre><code>randomDice: [5, 1, 3, 1, 4] 
  
  selectedDice: [0, 0, 3, 0, 4]
  </code></pre>
  
  <p>After that, the player rerolls only the dice he didn't select. And should get something like that:</p>
  
  <pre><code>randomDice: [4, 2, 3, 5, 4]
  </code></pre>
  
  <p>The reason I'm using two arrays is that the RandomDice is actually JButtons which later I loop.</p>
  
  <p>Here is some code snippet to give an idea:</p>
  
  <pre><code>rollDice.addActionListener( new ActionListener()
          {
              @Override
              public void actionPerformed(ActionEvent e)
              {
  
                  JToggleButton diceButtons[] = new JToggleButton[loadGame.getRolledDice().length];
                  int selectedDice[] = new int[loadGame.getRolledDice().length];
  
                  diceBox.removeAll();
  
                  for(int i = 0; i &lt; loadGame.getRolledDice().length; i++ ) {
                      // make new button name
                      diceButtons[i] = new JToggleButton(String.valueOf(loadGame.getRolledDice()[i]));
  
                      int dieKey = i;
                      diceButtons[i].addItemListener(new ItemListener() {
                          public void itemStateChanged(ItemEvent ev) {
                              if(ev.getStateChange()==ItemEvent.SELECTED){
  
                                  selectedDice[dieKey] = Integer.parseInt(diceButtons[dieKey].getText());
  
                                  System.out.printf(Arrays.toString(selectedDice));
  
                              } else if(ev.getStateChange()==ItemEvent.DESELECTED){
  
                                  selectedDice[dieKey] = 0;
  
                                  System.out.printf(Arrays.toString(selectedDice));
                              }
                          }
                      });
                      // add button to panel
                      diceBox.add(diceButtons[i]);
                  };
  </code></pre>
  
  <p>My question is how I can achieve the re-roll and keep the previously selected dice sides?</p>