Хранение объекта в concurrenthashmap, созданном с помощью конструктора - PullRequest
0 голосов
/ 23 октября 2019

Это мой код. Пытаюсь динамически добавлять сотрудников в таблицу concurrenthashmap. Там нет ошибки, но я получаю inputMismatchException. Эксперты, пожалуйста, помогите. КОД:

try {
        System.out.println("No of employees: ");
        int count = userdata.nextInt();
        System.out.println("count: " + count);

        System.out.println("enter employee details.");
        // with ConcurrentHashMap
        ConcurrentHashMap<Integer, employee> employeeDetails = new ConcurrentHashMap<>();
        int index = 0;
        do {
            employeeDetails.put(index, new employee(userdata.nextInt(), userdata.nextLine(), userdata.nextLine()));
            index++;
            count--;
        } while (count != 0);

        System.out.println(employeeDetails.toString());

        System.out.println("enter item to remove: ");
        String removeValue = userdata.nextLine();

        employeeDetails.forEach((k, v) -> {
            if (v.equals(removeValue)) {
                employeeDetails.remove(k);
            }
        });
        System.out.println("afer removal: \n" + employeeDetails.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }

Выход:

No of employees: 
2
count: 2
enter employee details.
1
name
city
java.util.InputMismatchException
...