+ 2
How can I validate my input is a string or not using hasnext() or hasnextline?
And what is the difference between has next() method and hasnextline() method ?
1 Resposta
+ 2
1)First of all, if you get input through for example a Scanner, nextLine and next return a String, whatever you enter. If you input 73, it would be handled as String ("73"). So you can use hasNextLine () or hasNext (), if it's true you're able to get a String.
2)If you input this:
A line filled with words
.next () would give you "A",
.nextLine() the whole line.