I want the user to press enter key to proceed, but I don't know how to detect enter key press.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
I'm assuming you mean in a console application.... You can use a
hasNextLinemethod will return true if they enter anything. You can follow that with a call to
nextLinewhich will remove that line from the input stream and return it to you. If you literally only want to proceed if they pressed only the enter key and nothing else then you can check if the string returned is the empty string.
Note that the
hasNextLinewill never return false if Scanner reading from
System.in. It will wait for input and then return true.