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 Using your New Tools Multiple Strings

Scanner vs readLine

Why do we use readLine instead of scanner? Is there a benefit to this or is it just an alternative?

1 Answer

andren
andren
28,558 Points

It's just an alternative way of getting input. It's a bit simpler to use than scanner and also allows you to specify a message that will be printed to the console when input is prompted for.

The disadvantage is that since it relies on the console class it won't work properly if you use any Java IDE like IntelliJ, eclipse, etc. Due to the way those programs run the Java code.

If you are used to using the Scanner class then there is nothing wrong with continuing to use that for these projects. Though the course challenges will mostly expect you to use the readLine method and likely won't let you pass if you use a Scanner instead.