I am creating a program that allows the user to enter the name of a contact to search for. If the contact is found, then the contact's other info (phone number and email) will be displayed.
My ArrayList looks like this:
ArrayList<Contact> contacts = new ArrayList<Contact>();
contacts.add(new Contact("Patrick McGee", "334-555-8860", "[email protected]"));
contacts.add(new Contact("John Appleseed", "142-555-6740", "[email protected]"));
contacts.add(new Contact("Matt Jordan", "213-555-2323", "[email protected]"));
contacts.add(new Contact("Kanye East", "255-434-9909", "[email protected]"));
contacts.add(new Contact("Derrick Flower", "144-555-1111", "[email protected]"));
I have variables: String name, String num, and String email.
Again, the user is asked to input the name (the first string of the arraylist).
If the name is found, then the contact will be printed (with all info). I have tried using BinarySearch in Collections, but that gave me errors that were very confusing. If more info is needed, feel free to ask.
Is there a method in searching like this? Thanks.