⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringtokenizerclassdemo.java

📁 卡内基梅陇大学的网上教程 ssd3第一单元的源码
💻 JAVA
字号:
package unitOne;
import  java.io.*;  // the PrintWriter class is here
import  java.util.*;  // the StringTokenizer class is here


/**
 * This class is a demo of class StringTokenizer
 *
 * @author  iCarnegie
 * version  1.0.0
 */
public class StringTokenizerClassDemo  {

	private static  PrintWriter  stdOut = new  PrintWriter(System.out, true);

	/**
	 * Main method, show the use of class StringTokenizer
	 *
	 * @param args  not used
	 */
	public static void  main(String[]  args)  {

		String  str = "This string has five tokens";

		// the default delimiter is the string "\t\n\r\f", i.e. whitespace
		StringTokenizer  tokenizer = new  StringTokenizer(str);


		stdOut.println("The input string:  " + str);
		stdOut.println();  // print a blank line

		// the following loop prints out each word in the string,
		// one to a line
		stdOut.println("The input string tokenized by " +
			"the default delimiter (whitespace):");

		int  i = 1;

		while (tokenizer.hasMoreTokens())  {
			stdOut.println("Token #" + i + ":  " + tokenizer.nextToken());
			++i;
		}

		stdOut.println();  // print a blank line

		// the delimiter can be specified as a
		// string using the following constructor
		tokenizer = new  StringTokenizer(str, "i");


		// this loop will print the four strings "Th",
		// "s str", "ng has f", "ve tokens", one to a line
		stdOut.println("The input string tokenized by \"i\":");
		i = 1;
		while (tokenizer.hasMoreTokens())  {
			stdOut.println("Token #" + i + ":  " + tokenizer.nextToken());
			++i;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -