Sharkmen
Sharkmen

Reputation: 63

nextLine ignoring input, but next() don't - why have i clear scanner?

I had problem where nextLine was ignoring user input. After some research, I found that I have to clear the Scanner using in.nextLine(), but can you tell me why? I would like to know what I'm doing when I use this:

String edit = in.nextLine();

switch (edit) {
    case "name":
        System.out.println("Enter new name for " + items.get((editItem - 1)).getName());
        String newName = in.nextLine();
        items.get((editItem - 1)).setName(newName);

Upvotes: 0

Views: 77

Answers (1)

Related Questions