permaculture playing cards*
The moose likes Beginning Java and the fly likes Scanner class and character input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scanner class and character input" Watch "Scanner class and character input" New topic

Scanner class and character input

michael delta
Ranch Hand

Joined: Aug 11, 2009
Posts: 35

Why isn't scanner class an efficient way to receive input from the keyboard?Which way suits this need?
Greg Stevens
Ranch Hand

Joined: Jul 23, 2009
Posts: 41
I'm just guessing here, but I think it would be because a Scanner is not buffered.
Greg Stevens
Ranch Hand

Joined: Jul 23, 2009
Posts: 41
I found this.

I just read the content of that link more carefully, and I think it might not be quite right.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38001
The only reason Scanner isn't efficient is because keyboards are slow. Scanner itself is very efficient and versatile, once you have found out about 1\n being parsed as integer 1 followed by an empty line. Scanner is a far better way to read from the keyboard than the old Reader method.
It is sorta covered in the JavaRanch Style Guide.
subject: Scanner class and character input
Similar Threads
Using Scanner to read a single character
how can i separate string?
TextIO class - Matter copied from unrelated thread