I am very familiar with using java.util.Scanner
with next()
, hasNext()
, nextInt()
, nextLine()
, and the like to parse input.
Is there something else I should use in Scala?
This data isn't structured according to a grammar; it's more ad-hoc than that.
For example, lets say I had a inventory. Each line of input starts with the name, then has the quantity of those items, then has the ids for those items
Firetruck 2 A450M A451M
Machine 1 QZLT
Keyboard 0
I see that Console
has methods such as readInt()
, but that reads an entire line of input; the equivalent of nextInt()
doesn't seem to exist.
java.util.Scanner
obviously does the trick. But is there something else I should use (for example, something that returns Scala rather than Java types)?
No there is no equivalent Scala implementation. But I don't see a reason for one as java.util.Scanner would work perfectly fine and all java primitives types would be converted to Scala types implicitly.
So as for "for example, something that returns Scala rather than Java types", Scanner will return scala types when used in scala.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With