title: Checking for duplicated data in Java array list
body: <p>I am writing a basic library app which uses an arraylist of books in its book repository class.</p>
  <p>I can add books to the list using a books.add(new book(...))  command as shown below.</p>
  <p>However, is there a way I can notify the user if they try adding a book ISBN which already exists?</p>
  <pre><code>    // constructor
      public Book(String isbn, String title, String author, String genre, int year, int quantity, int numCheckedOut) {
          super();
          this.isbn = isbn;
          this.title = title;
          this.author = author;
          this.genre = genre;
          this.year = year;
          this.quantity = quantity;
          this.numCheckedOut = numCheckedOut;
      }
  
      public String getIsbn() {
          return isbn;
      }
  
      public String getTitle() {
          return title;
      }
  
      public String getAuthor() {
          return author;
      }
  
      public String getGenre() {
          return genre;
      }
  
      public int getYear() {
          return year;
      }
      
      public boolean checkOut() {
          if (numCheckedOut &gt;= quantity) {
              return false;
          }
          numCheckedOut++;
          return true;
      }
      
      public boolean checkIn() {
          if (numCheckedOut &lt;= 0) {
              return false;
          }
          numCheckedOut--;
          return true;
      }
  
      public int getQuantity() {
          return quantity;
      }
  
      public int getNumCheckedOut() {
          return numCheckedOut;
      }
  }
  </code></pre>
  <pre><code>public class BookRepository {
      
      private ArrayList&lt;Book&gt; books = new ArrayList&lt;&gt;();
      
      public BookRepository() {
          books.add(new Book(&quot;1&quot;, &quot;To Kill a Mockingbird&quot;, &quot;Harper Lee&quot;, &quot;Fiction&quot;, 1960, 4, 0));
  }
  </code></pre>