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