天天看點

java字元串分解 StringTokenizer用法

stringtokenizer有兩個常用的方法:

1.hasmoreelements()。這個方法和hasmoreelements()方法的用法是一樣的,隻是stringtokenizer為了實作enumeration接口而實作的方法,從stringtokenizer的聲明可以看到:class stringtokenizer implements enumeration。

2.nextelement()。這個方法和nexttoken()方法的用法是一樣的,傳回此 stringtokenizer 的下一個标記。

stringtokenizer的三個構造方法:

1.stringtokenizer(string str)。預設以” \t\n\r\f”(前有一個空格,引号不是)為分割符。

token1:www

token1:ooobj

token1:com

2.stringtokenizer(string str, string delim)。指定delim為分割符。

token:www

token:ooo

token:j

token:com

**3.stringtokenizer(string str, string delim, boolean returndelims)。**returndelims為true的話則delim分割符也被視為标記。

token2:www

token2:.

token2:ooobj

token2:com