Im writing a method to return a specific record in an array however it throws up two errors and Im not sure how to fix it. Can anyone explain what I'm doing wrong?
public String find(String searchName)
{ // ERROR - MISSING RETURN STATEMENT
Iterator<TelEntry> iterator = Directory.entries.iterator();
boolean hasFound = false;
while (iterator.hasNext())
{
TelEntry entry = iterator.next();
if (entry.name.equalsIgnoreCase(searchName)) {
return entry.name + entry.telNo;
hasFound = true; // ERROR UNREACHABLE STATEMENT
}
}
if (hasFound==false)
{
System.out.println("sorry, there is noone by that name in the Directory. Check your spelling and try again");
}
}
Can anyone explain what I've done wrong?