Welcome! Today, we will explore creating a simple address book application using Java's HashMap
. This task will help you understand how to manipulate a HashMap
in Java, focusing on adding, retrieving, and deleting entries. By the end of this lesson, you'll have a solid grasp of these fundamental operations.
In this task, we will implement three methods to manage our address book:
addContact(String phoneNumber, String name)
: Adds a new contact. Returnsfalse
if the contact already exists; otherwise, it adds the contact and returnstrue
. For this task, let's assume names do not change, so it's not allowed to overwrite an existing contact's name.getContact(String phoneNumber)
: Retrieves the name for a givenphoneNumber
. Returnsnull
if the contact does not exist.deleteContact(String phoneNumber)
: Deletes a contact with the givenphoneNumber
. Returnstrue
if the contact exists and is deleted, otherwise.
