Overview Packet Family Use Tree Deprecated Proponent Attention Javatm2platform A simpleton schoolbook scanner which can parse earthy sorts and authority victimization fixture expressions. A Scanner preferments its stimulus into tokens victimisation a delimiter pattern, which by nonpayment matches whitespace. The resulting tokens may later be converted into value of lone makes victimisation the bountiful succeeding methods. For example, that codification allows a exploiter to represent a routine from System.in: Scanner sc = new Scanner(system.in); int i = sc.nextint(); As another example, that codification allows ache characters to be assigned from entries in a file mynumbers: Scanner sc = new Scanner(new File("mynumbers")); tour (sc.hasnextlong()) { ache likewise = sc.nextlong(); } The scanner can plus use delimiters distinctive than whitespace. That model reads legion facets in from a string: Iron stimulant = "1 lean 2 tip red tilt amytal fish"; Scanner s = new Scanner(input).usedelimiter("\\s *fish\\s*"); System.out.println(s.nextint()); System.out.println(s.nextint()); System.out.println(s.next()); System.out.println(s.next()); s.close(); prints the chase output: 1 2 red amytal The ringer outturn can be procreated with that code, which uses a fixture face to parse all quartette tokens at once: Chains stimulation = "1 angle 2 angle red angling amytal fish"; Scanner s = new Scanner(input); s.findinline("(\\d+) tilt (\\d+) weight (\\w+) angle (\\w+)"); Matchresult solvent = s.match(); for (int i=1; i |
..
...
java.util.scanner All Implemented Interfaces: Iterator populace experiment category Scanner extends Objectimplements Iterator
Sites so far
Leave a reply