java - searchByEmail 方法不起作用

标签 java search hashmap

我对这个方法有疑问。当用户要求时,它不会输出正确的搜索。

这是我的代码:

System.out.println("Search by Email.");
Employee employeeSearchEmail = MenuMethods.userInputByEmail();
Store.searchByEmail(employeeSearchEmail.getEmployeeEmail());

public Employee searchByEmail(String employeeEmail) {
    for (Employee employee : map.values()) {
        System.out.println(employee);
        map.equals(getClass());
        map.equals(employee.getEmployeeEmail());
        employee = new Employee(employeeEmail);
        ;
        return employee;
    }
    return null;
}

public static Employee userInputByEmail() {
    // String temp is for some reason needed. If it is not included
    // The code will not execute properly.
    String temp = keyboard.nextLine();
    Employee e = null;
    System.out.println("Please enter the Employee Email:");
    String employeeEmail = keyboard.nextLine();
    // This can use the employeeName's constructor because java accepts the
    // parameters instead
    // of the name's.
    return e = new Employee(employeeEmail);

}

最佳答案

问题是你的程序中没有这样的 if 条件:

public Employee searchByEmail(String employeeEmail) {
        for (Employee employee : map.values()) {
            map.equals(getClass());
            if (map.equals(employee.getEmployeeEmail())){
                System.out.println(employee);
                return employee;
            }
        }
        return null;
    }

这一行: System.out.println(员工);

它将打印员工对象,直到找到匹配项,当匹配时,它将返回该员工对象。

关于java - searchByEmail 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11592316/

相关文章:

java - 使用双键创建 HashMap

Java - 添加一个对象而不引用原始对象

java - 运行简单的 Camel ReSTLet 演示项目时遇到问题?

java - 对于非常大的数据集,我应该使用 `HashSet` 还是 `TreeSet`?

java - onPause() 没有 Intent ,onResume() 没有 onCreate()

java - 向我的 HashMap 添加键值对时遇到困难

java - 两个远程集群之间的 DistCp 容错

javascript - 在 react 中搜索关键字列表

php - PHP/MySQL 中的多词搜索

c - 在 C 中使用 strstr 函数搜索文本