public String nameToPhone(String inputName) {
/* (c) Allow the user to search a contact’s phone number using his/her name. */
Pattern p;
Matcher m;
// Store name as pattern
p = Pattern.compile(inputName);
// Match pattern with array name
m = p.matcher(this.name);
if (m.matches())
return this.phoneNum;
else
return null;
}
The function will be called with System.out.print(phonebookArray[i].nameToPhone)
Expected output:
display only phone number if searched name exist
Actual output:
else return nullwill display phone number and also "null" if name existelse return ""will display phone number and a blank line if name exist
The issue is return null will display null and return "" will display a blank line. How can I return absolutely nothing?