The usage and similarities and differences between Scanner and console

Source: Internet
Author: User
Tags readline

All I know is that these two classes can be used to enter
Scanner s=new Scanner (;
String Txt1=s.nextline ();

Console c=new console ();
String Txt2=c.readline ();

And the console can be used to read the password, C.readword ()
The characters entered by scanner () are displayed. The scanner class operation is more than the console class

Both are to obtain user input content;
The first approach is to use the console class, which is accessed through system objects. The ReadLine () method of the console class gets input from the user command line and returns a string to the calling program. The advantage of using this method is that you don't need to import anything because the system class is part of the ubiquitous Java.lang package available. The disadvantage of using the console method is that it usually does not work in an IDE like Ecliple. Console can only ensure that you are working directly on the JVM running Java code, or you will be warned.

System.Console (). ReadLine ();//input, return a string

The second approach is to use the scanner class, which is in the package. Using the scanner class is usually a two-step process, although you can hide it and push it into a, long, strung way to invoke:

Scanner Scanner = new Scanner (;

String input = ();

/* or String input = (new Scanner ( Next ();

Unlike the console class, the scanner class works equally well with the command line and standard Ides, such as Eclipse.
What is the IDE.
IDE (integrated Development Environment), integrated development environment.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.