title: Method to add unique object instance into an ArrayList is not working
body: <p>First of all: I am new to Java and this site, this is my first post here. I have searched on both Google and this site regarding my question and found some (a lot) of similar posts, but I can't found one that helps me with my coding problem.</p>
  <p>I have two classes: <strong>Library</strong> and <strong>Book</strong>. For the last four hours, I have been trying to write a method that adds a book to the Library (to an ArrayList) if it's unique. If it's not unique, a message will be printed saying that the Library already has the book. </p>
  <p><strong>Class:</strong> Library </p>
  <p><strong>Field:</strong> </p>
  <pre><code>private ArrayList&lt;Book&gt; bookList;
  </code></pre>
  <p><strong>Constructor:</strong> </p>
  <pre><code>bookList = new ArrayList&lt;Book&gt;();
  </code></pre>
  <p><strong>Method:</strong></p>
  <pre><code>public void addBook(Book bookTitle)
  {
  for(Book bookId:bookList) {
  if (bookTitle.equals(bookId)) {
  bookList.add(bookTitle);
  System.out.println(&quot;Book registered.&quot;); }
  else { System.out.println(&quot;This book is not unique&quot;; }                
  } 
  </code></pre>
  <p>}</p>
  <p>I do not get any compilation error but it's not working. The object is not added to my ArrayList, no message is printed. I have also tried with: </p>
  <pre><code>if (bookId != bookTitle)
  </code></pre>
  <p>without result.</p>
  <p>Hope someone here can help and explain to me what I am doing wrong, it would be greatly appreciated.</p>