Tokenizing with Scanner : Scanner « Utility Classes « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Utility Classes » Scanner 
8.23.3.Tokenizing with Scanner
import java.util.Scanner;

public class MainClass {
  public static void main(String [] args) {
    boolean b2, b;
    int i;
    String s, hits = " ";
    Scanner s1 = new Scanner(args[0]);
    Scanner s2 = new Scanner(args[0]);
    while(b = s1.hasNext()) {
      s = s1.next();  hits += "s";
    }
    while(b = s2.hasNext()) {
      if (s2.hasNextInt()) {
        i = s2.nextInt();  hits += "i";
      else if (s2.hasNextBoolean()) {
        b2 = s2.nextBoolean();  hits += "b";
      else {
        s2.next();  hits += "s2";
      }
    }
    System.out.println("hits " + hits);
  }
}
8.23.Scanner
8.23.1.Scanning Text
8.23.2.You can use a regular expression which specifies a class or group of characters in Scanner.
8.23.3.Tokenizing with Scanner
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.