Given the following details I need to write a method which returns an Object Person:
public class Person {
private String firstName;
private String lastName;
private int deskNo;
private String departmentName;
...
}
// this class also contains get methods for each argument
Objects Person are stored in a HashMap, where Key is same as lastName for each Object. Value is obviously Person Object.
private final Map<String, Person> employeeHM = new HashMap<>();
...
employeeHM.put("Doe", new Person("Jon", "Doe", 14, "Sales");
I approached this problem with several solutions but failed in each instance. Is there a way do directly compare the firstName with lastName and return matching Object? One of my ideas was to use a Set or a Colleciton, but I am fairly sure this is overcomplicating things.
@Override
public Person findPersonByFirstName(String firstName) {
// ?
}
lastNameas the key, you won't be able to have both John and Jane Doe in your map.