How-to articles, tricks, and solutions about JAVA.UTIL.SCANNER

How to put a Scanner input into an array... for example a couple of numbers

To put input from a Scanner into an array in Java, you can use a loop to read the input and store it in the array.

Scanner is skipping nextLine() after using next() or nextFoo()?

It is common for the Scanner class's next() and nextFoo() methods (where Foo is any primitive type such as Int, Double, etc.) to skip over newline characters in the input. This is because these methods are designed to read only the next token in the input

Take a char input from the Scanner

To take a character input from the Scanner in Java, you can use the next() method to read a string and then use the charAt(int index) method to get the first character of that string. Here's an example:

Using scanner.nextLine()

Scanner.nextLine() is a method of the Scanner class in Java that reads a line of text from the input.