Reputation: 63
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
Reputation: 150
Please visit the below links for better understanding why nextline() does not read input :
Scanner is skipping nextLine() after using next() or nextFoo()?
Upvotes: 2