Details

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

indexOf returns 2

Details

phonebook class

Things are getting a little complicated. It would be good to look at some details.

  1. An ArrayList of entries is constructed
  2. Several Entry objects are put into the list.
  3. A target Entry object is created.
  4. The indexOf() searches for the target in the list.
    • The equals(Object) method of Entry is used.
    • The picture shows the third comparison (which returns true).
  5. A match is found at cell number 2

The indexOf(Object) method is a member of the ArrayList, but it uses the equals(Object) method of Entry.

QUESTION 25:

Would playing with the program help?