Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Censoring Words - Using String Equality

Christian Baliker
Christian Baliker
453 Points

How is Console different than Scanner?

Hi, I was wondering what the difference was between console and scanner when prompting the user for something? In my class we use Scanner, so it would be interesting to know how these to differentiate.

1 Answer

Sara Lopes
Sara Lopes
1,556 Points

Hi,

As per https://stackoverflow.com/questions/17637032/bufferedreader-vs-console-vs-scanner

Scanner Since Java 1.5 Doesn't throw checked exceptions Can read lines, whitespace-delimited tokens, regex-delimited tokens, and numbers Difficult to read single characters

Console Since Java 1.6 Doesn't throw checked exceptions Can read lines Underlying reader can read chars and char arrays (stops at line bounds) Not always available (e.g. Eclipse) Can read passwords (i.e. read without displaying the characters)

Thank you