I have an array list of book objects where one of the class fields is title. I want to search through the array for a book with a specific title value.
public void getBook(String bookTitle) throws SQLException {
ArrayList<Book> books = getAllBooks();
for (int i = 0; i < books.size(); i++) {
Book b = books.get(i);
if (b.getTitle() == bookTitle) {
System.out.println(b.getTitle());
}
}
}
As far as I can tell the code above should search through the array list for book objects and compare their title field with the string passed into the function. If the strings match then the book title will be printed to console. However nothing happens. Help :(