当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java StringTokenizer nextToken()用法及代码示例


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


相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 StringTokenizer nextToken() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。