Summary of Scanner class

Source: Internet
Author: User

1. Constructors

Scanner (File Source)
Scanner (InputStream Source)
Scanner (String Source)

Reference: HTTP://BLOG.SINA.COM.CN/S/BLOG_7014AD5C01018SOV.HTM2. Methods
1Scanner in =NewScanner (system.in);//Open Scanner2         //First, Hasnext ()3System.out.println (In.hasnext ());//output Time: The first input data is accepted to "save and Wrap" instruction ("carriage return")4         5         //second, see "Default split Mode"6Pattern p =In.delimiter (); 7SYSTEM.OUT.PRINTLN (P);/** Output: \p{javawhitespace}+ < white space > */8          9         //Third, modify the "default split mode"TenP =pattern.compile ("_");  OneIn.usedelimiter (P);//Modify Next (), Nextxxx () (except Nextline) method default "split mode" ASYSTEM.OUT.PRINTLN ("Test Split method" Enter the test string; ");  -String s =in.next ();/** Input: A_b_c */ -System.out.println (s);/** output; changed (to ' _ '): ' A ' | | No change (default ' space '): "A_b_c" */ the          -         //Iv. difference between next () and nextline () -System.out.println ("" Test Next and Nextline "Please enter the test string;"); -                                        //Accept Input +s =in.next ();/** Input: A_b_c */ -                                     //s= "A", the cursor moves to the space after C +                                     //whether the cursor is at the beginning of the line?no--> does not accept input (returns the last line ("A_b_c" in the row) after the C part--empty string) As =in.nextline ();//s= "", Line break at                                        //is the cursor at the beginning of the line? yes--> Accept Input -s =in.nextline ();/** Input: A_b_c */ -                                        //s= "A_b_c", line break -                   /** - * Summary: - * Same point: "Save and line break" condition--carriage return in * Different points: Scanning mode, segmentation method -                    * */ to        //v. Close () +In.close ();//turn off the scanner

Summary of Scanner class

Related Article

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: info-contact@alibabacloud.com 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.