I have made a phone bill system takes input of phone number called, date of the call and call length. it the saves it in to a text file. what i have not been able to do is search the text file for the phone number.
My coding
just do linear search (iterating over your phone list) :
public static List<Phone> searchPhone(final String phoneNumber, final List<Phone> phoneList) {
    List<Phone> matchedPhone = new ArrayList<Phone>();
    for(Phone phone: phoneList) {
        if ( phone.getphoneNumber().equals(phoneNumber) ) { 
            matchedPhone.add(phone);
        }
    }
    return matchedPhone;
}
also for readability, don't make your method parameter as output. its not good practice, so you should change your method from:
static void readList(List<Phone> phoneListIn) {
}
to:
   static List<Phone> readList(final String fileName) {
   }
output arguments should be avoided as possible as you can
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With