title: Checking for duplicates and moving to the next element
body: <p>I have a simple program consisting of a String array and a String arraylist. The program randomly chooses a String from the array and checks if that String also exists in the arraylist. If it does, then a different String is chosen. Right now the program runs fine, but I'm not sure how efficient my code is, since I have the same line of code running twice - which I think is bad practice.</p>
  
  <pre><code>`import java.util.ArrayList;
  import java.util.List;
  import java.util.Random;
  
  public class Main {
  
  public static String[] rooms1 = new String[] {
          "Library",
          "Kitchen",
          "Study",
          "Conservatory",
          "Ballroom",
          "Lounge",
          "Hall",
          "Billiard Room",
          "Dining Room"
      };
  
  public static List&lt;String&gt; rooms2 = new ArrayList&lt;String&gt;();
  
  public static void addRooms() {
      rooms2.add("Garage");
      rooms2.add("Bar");
      rooms2.add("Library");
      rooms2.add("Bathroom");
      rooms2.add("Lounge");
      rooms2.add("Dining Room");
  }
  
  public static void main(String[] args) {
      addRooms();
      Random random = new Random();
      String roomChosen = rooms1[random.nextInt(rooms1.length)];
      while (rooms2.contains(roomChosen))
          roomChosen = rooms1[random.nextInt(rooms1.length)];
      System.out.println("Player has entered the " + roomChosen);
  }
  }
  </code></pre>
  
  <p>`</p>
  
  <p>The line of code that repeats itself is <code>roomChosen = rooms1[random.nextInt(rooms1.length)];</code></p>