Relatively new to Java and probably a very trivial question but I have been getting super confused. Suppose I have the following program:
Scanner keyboard = new Scanner(System.in);
System.out.println(keyboard.hasNext());
When I run this program, it prompts me to enter something, I press enter and then the console output is (obviously) true. But precisely, how does the hasNext() method work? From the Oracle website: returns true if the scanner has another token in its input. In my example, there only one input . How exactly is being read and why exactly do I get true if there's no next input into the program? From what I understand the scanner breaks the input into tokens based on the delimiter (in this case we have the default delimiter), so in my case, say i enter "test", then press enter. The scanner reads up to the white space but then there's no next token to read? Then why is hasNext true?
Hopfully not too silly but I am genuinely confused. Many thanks!
I have tried various runs on the above code and i always get true. (obviously ctrl+D , ctrl+C kill the program)