title: In java, how to replace a duplicate number in an ArrayList?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/203984/how-do-i-remove-repeated-elements-from-arraylist">How do I remove repeated elements from ArrayList?</a>  </p>
  </blockquote>
  
  
  
  <p>I want to replace a duplicate number (if any) that i store in an ArrayList. I obtianed the numbers for a Random variable. Here is the class.</p>
  
  <pre><code>import java.util.*;
  
  public class RandomNumbers {
  // instance variables
  private ArrayList&lt;Integer&gt; randomNumberList = new ArrayList&lt;Integer&gt;(); 
  private Random randomNums = new Random();
  
  public RandomNumbers(){
      // generating and adding random numbers to the list
      for (int i=0; i&lt;MemoryGame.totalAnswers; i++)
          randomNumberList.add(randomNums.nextInt(32));
  
      System.out.println("Numbers in the list: " + randomNumberList);
      System.out.println("");
  }
  
  public ArrayList&lt;Integer&gt; getRandomNumbers(){
      return randomNumberList;
  }
  }
  </code></pre>
  
  <p>My school book tells me how to add,remove and retrieve a number, but not how to replace one that is duplicated.</p>
  
  <p>thanks.</p>