Here you can find the source of Tokenize(String s, String s2, String s3)
public static void Tokenize(String s, String s2, String s3)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static void Tokenize(String s, String s2, String s3) { StringTokenizer tok = new StringTokenizer(s, " "); // Cara cepat untuk mendapatkan jumlah token System.out.println("Jumlah token: " + tok.countTokens()); int i = 0; while (tok.hasMoreTokens()) { System.out.println(tok.nextToken()); i++;// w w w . ja v a 2 s .co m } // Mendapatkan jumlah token (lebih lambat) System.out.println("Jumlah token: " + i); // Karakter pemisah adalah !, ?, dan . StringTokenizer tok2 = new StringTokenizer(s2, "!?."); while (tok2.hasMoreTokens()) { System.out.println(tok2.nextToken()); } Scanner scan = new Scanner(s3).useDelimiter(" "); while (scan.hasNext()) { System.out.println(scan.next()); } while (scan.hasNextInt()) { // Scan sebagai int System.out.println(scan.nextInt()); } } }