Project : My personal Library


import java.util.HashMap;
// This library helps to find completion status of the books //
class Library{
public Library() {

public void getFinishedBooks(HashMap<String, Boolean> library) {

if (library.size() < 1) {
  System.out.println("The HashMap is empty.");
} else {
  for (String book: library.keySet()) {
    if (library.get(book) == true) {


public static void main (String args) {
HashMap<String, Boolean> myBooks = new

myBooks.put("Road Down The Funnel", true);
myBooks.put("Rat: A Biology",false);
myBooks.put("3D Food Printing", false);

Library myLibrary = new Library();


So now my code works but I wonder this: Why the result return to the book " TimeIn" first then second is the book “Road Down The Funnel”. although the book “Road Down The Funnel” was called first on the code.

The same thing happen when I set the condition: if (library.get(book) == false)

The book “3D FootPrinting” appeared first on the box and then on the second line is the book “Rat: A Biology” although the book “Rat: A Biology” was called before 3D FootPrinting.


if we look at the documentation:

we find this in the first paragraph:

This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.