why prefer one over the other? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why prefer one over the other?

When or why would one prefer to use the System.in stream over the Scanner? They both read input from the console(though with the System.in you have to typecast to String in order to read in a new string, because it reads in bytes?so far i got)... but why prefer one over the other?

30th May 2018, 7:39 PM
loeckchen[INACTIVE]
1 Answer
+ 2
Scanner has a nice API to deal with the input in a nice way, like what character to separate on when next() is called. Just like you can use a knife to eat soup but probably shouldn't, everything has a use case that it is designed for. InputStream can take data, Scanner helps to deal with that data in a useful way. Usually a stream is passed to some other object so that it can be handled effectively
31st May 2018, 10:02 PM
Dan Walker
Dan Walker - avatar