StringTokenizer類的nextToken()方法用於從此StringTokenizer依次返回下一個標記。
用法:
public String nextToken()
參數:該方法不帶任何參數。
返回值:該方法返回字符串令牌化程序行中存在的下一個令牌。
下麵的程序說明StringTokenizer的nextToken()方法的用法:
示例1:
// Java code to illustrate nextToken() method
import java.util.*;
public class StringTokenizer_Demo {
public static void main(String args[])
{
// Creating a StringTokenizer
StringTokenizer str_arr
= new StringTokenizer(
"Lets practice at GeeksforGeeks");
// Displaying the Tokens
while (str_arr.hasMoreTokens()) {
System.out.println("The Next token: "
+ str_arr.nextToken());
}
}
}
輸出:
The Next token: Lets The Next token: practice The Next token: at The Next token: GeeksforGeeks
示例2:
// Java code to illustrate nextToken() method
import java.util.*;
public class StringTokenizer_Demo {
public static void main(String args[])
{
// Creating a StringTokenizer
StringTokenizer str_arr
= new StringTokenizer(
"Welcome to GeeksforGeeks");
// Displaying the Tokens
while (str_arr.hasMoreTokens()) {
System.out.println("The Next token: "
+ str_arr.nextToken());
}
}
}
輸出:
The Next token: Welcome The Next token: to The Next token: GeeksforGeeks
相關用法
- Java StringTokenizer hasMoreTokens()用法及代碼示例
- Java StringTokenizer nextElement()用法及代碼示例
- Java StringTokenizer countTokens()用法及代碼示例
- Java StringTokenizer hasMoreElements()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 StringTokenizer nextToken() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。