1 Error on line 12(CodeAcademy Learn Java, personal library)

https://www.codecademy.com/courses/learn-java/projects/personal-library

import java.util.HashMap;
public class Library {
 public Library () {
    
  }
  public void getFinishedBooks(HashMap<String,Boolean> library) {
    if (library.size() < 1) {
      System.out.println("empty,wtf!!##@@");
    }
    else {
      for (Boolean book : library.keySet()) {
        if (book == true) {
          System.out.println(book);
        }
      }
    }
  }
  public static void main(String [] args) {
    HashMap<String,Boolean> myBooks = new HashMap<String,Boolean>();
    myBooks.put("Road Down The Funnel", true);
    myBooks.put("Rat: A Biology", false);
    myBooks.put("TimeIn", true);
    myBooks.put("3D Food Printing", false);
    Library myLibrary = new Library();
    myLibrary.getFinishedBooks(myBooks);
    
  }
}

Library.java:11: error: incompatible types: String cannot be converted to Boolean
for (Boolean book : library.keySet()) {
^
1 error

I dont understand, how i can fix error. Can anyone help?

here:

for (Boolean book : library.keySet())

book is not of type boolean, book will contain the hashmap keys (so titles of books), not the values belonging to keys, which are booleans.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.