Java Scanner Usage Tokenize(String s, String s2, String s3)

Here you can find the source of Tokenize(String s, String s2, String s3)

Description

Tokenize

License

Open Source License

Declaration

public static void Tokenize(String s, String s2, String s3) 

Method Source Code

//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());
        }

    }
}

Related

  1. splitToDouble(String input)
  2. stringToArray(String str)
  3. stringToDoubleList(String s)
  4. swapElements(int length, int maxValue)
  5. termInput()
  6. toNumeric(String ip)
  7. toWords(String content)
  8. transformTXTandANNtoRQS(String TXT, String ANN)
  9. trim(String s)