How to clear the buffer? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to clear the buffer?

14th Jul 2019, 1:38 PM
Igor Matos 09
Igor Matos 09 - avatar
4 Answers
+ 1
What buffer you talking about?
15th Jul 2019, 2:23 AM
John Wells
John Wells - avatar
0
the console
15th Jul 2019, 9:00 AM
Igor Matos 09
Igor Matos 09 - avatar
0
If you want to empty System.in buffer prior to outputing a prompt and reading response for non SoloLearn code, you can test the Scanner with hasNext(). If true, you can read it with next(). Repeating this until false will empty the buffer. In SoloLearn, it also empties the buffer, but you can't enter any more responses, since all input must be given prior to running the program. Note: it might be enough to read the end of line with nextLine().
15th Jul 2019, 12:41 PM
John Wells
John Wells - avatar
0
Every nextZ() has an equivalent hasNextZ() to test to see if the buffer has a Z in it, where Z is things like Boolean, Double, Float, Int, Line, Long, and Short.
15th Jul 2019, 12:48 PM
John Wells
John Wells - avatar