集册 Java实例教程 StringTokenizer:指定分隔符

StringTokenizer:指定分隔符

欢马劈雪     最近更新时间:2020-01-02 10:19:05

640
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
StringTokenizer:指定分隔符


/*

  Java StringTokenizer - Specify Delimiter example.

  This example shows how a specify a delimiter for StringTokenizer object.

  The default delimiters are

  \t character (tab),

  \n character (new line),

  \r character (carriage return) and

  \f character (form feed).

*/

 

import java.util.StringTokenizer;// from 时 代 J     a    v  a - nowjava.com

 

public class Main {

 

  public static void main(String[] args) {

    //1. Using StringTokenizer constructor

    StringTokenizer st1 = new StringTokenizer("Java|StringTokenizer|Example 1", "|");

   

    //iterate through tokens

    while(st1.hasMoreTokens())

      System.out.println(st1.nextToken());

   

    //2. Using nextToken() method. Note that the new delimiter set remains the

    //default after this method call

    StringTokenizer st2 = new StringTokenizer("Java|StringTokenizer|Example 2");

   

    
展开阅读全文