2015年10月26日 星期一

[Java]StringTokenizer

今天介紹一個除了split()方法以外,分割String的方法
StringTokenizer的方法主要有下列幾個

countTokens():可以知道你的String被Tokenizer分成幾段
hasMoreTokens():檢查StringTokenizer是否還有Token
nextToken():將StringTokenizer的下一個Token用String表示

以下是簡單的範例:



import java.util.StringTokenizer;



public class StringDemo {


 public static void main(String[] args) {

  String demo = "String,int,long,double";



  StringTokenizer st = new StringTokenizer(demo,",");

 

  System.out.println("st has "+st.countTokens()+"tokens");

 

  while(st.hasMoreTokens()){

   System.out.println();

  }

 }

}

1 則留言:

  1. Merkur 20C - Merkur 20C Safety Razor - Deccasino
    Merkur 바카라사이트 20C is a chrome finished, 메리트카지노 very compact safety razor. Merkur 20C has the same great quality as the Merkur 20C, งานออนไลน์ as its handle is longer and longer.

    回覆刪除