I have an Address Book program it can:
- Add an Entry
- Delete an Entry
- Update an Entry
- View all Entries
- View specific entry
All functions well, but my problem is I want to check once the user has inputted a NAME if it already exists
This is my addEntry method:
public void addEntry() {
entry[counter] = new AddressBookEntry();
entry[counter].setName(getNonBlankInput("Enter Name: "));
entry[counter].setAdd(getNonBlankInput("Enter Address: "));
entry[counter].setPhoneNo(getNonBlankInput("Enter Phone No.: "));
entry[counter].setEmail(getNonBlankInput("Enter E-mail Address: "));
counter++;
}
Please help me to add some conditions that will filter the user input. Like, if the user inputted a name ALREADY EXISTS.
Thanks in advance
Use HashMap as storage with Keys as
UserName. You can check if user exists by performing containsKey method of HashMap. Also, it is advisable to