Java personal library


The error notification is : error: cannot find symbol
for (String book : library.KeySet()) {
symbol: method KeySet()
location: variable library of type HashMap<String,Boolean>
1 error

And the code is following:

import java.util.HashMap;

public class Library{
  public Library(){
  public void getFinishedBooks (HashMap<String, Boolean> library){ 
    if(library.size() < 1){
    else {
      for (String book : library.KeySet()) {
        if (library.get(book) == true) {

      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("3D Food Printing",false);
      Library myLibrary = new Library();

I double checked my result by compared with video solution, I found we did almost same, I would like to know what’s wrong with my code?


Simple :slight_smile:
The keySet() method is case sensitive.
Rather than for (String book : library.KeySet()) { you should use for (String book : library.keySet()) {

Also, just another pointer, library.get(book) returns true, so you can avoid the extra == true in this case