Compare object fields in if statement and 2 arraylists : <p>I'm trying to do a method that checks if a book is rented and then if the book is in a directory. But I get a variable might not have been initialized error on checkIsBookAvailableToRent. I wonder it means the variable may be the out of scope. Can you help me improve this method, please?</p>

<pre><code>package com.company.model;

import java.util.ArrayList;
import java.util.List;

public class BookDirectory {

private static List&lt;Book&gt; bookDirectoryList = new ArrayList&lt;Book&gt;();
RentDirectory rentedBooksList = new RentDirectory();
Book book = new Book("");

public boolean isBookAvailableToRent(String title){

    boolean checkIsBookAvailableToRent;
    book.setTitle(title);

    for (Book bookInRentDirectory : rentedBooksList.getRentedBooks()) {
        if (bookInRentDirectory.getTitle().equals(book.getTitle())) {
            checkIsBookAvailableToRent = false;
        }
        else {
            for (Book bookInBookDirectory : bookDirectoryList) {
                if (bookInBookDirectory.getTitle().equals(book.getTitle())) {
                    checkIsBookAvailableToRent = true;
                }
                else {
                    checkIsBookAvailableToRent = false;
                }
            }
        }
    }
    return checkIsBookAvailableToRent;
}

public List&lt;Book&gt; getBookDirectory() {
    return bookDirectoryList;
}
</code></pre>

<p>}</p>
