+ 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 ?

22nd Jan 2018, 1:09 PM
jomar ibarra
jomar ibarra - avatar
1 Answer
+ 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.
22nd Jan 2018, 1:51 PM
Jonas Schröter
Jonas Schröter - avatar