title: Find the difference between two collections in Java 8?
body: <p>I am trying to make a <code>List</code> of all of the books in one <code>Collection</code> that are not present in another. My problem is that I need to compare based on book ID, so I can't just test to see whether a book in the first is contained in the second, I have to determine whether any book in the second collection has the same ID as a book in the first.</p>
  
  <p>I have the below code to compare two collections of books and filter the first collection:</p>
  
  <blockquote>
  <pre><code>List&lt;Book&gt; parentBooks = listOfBooks1.stream().filter(book-&gt;
    !listOfBooks2.contains(book)).collect(Collectors.toList());
  </code></pre>
  </blockquote>
  
  <p>The code doesn't work correctly because I am comparing the objects themselves. I need to compare the objects based on the bookId instead of the whole book object. How should I change the code so it can do the comparison based on the bookId (book.getId())?</p>