Home » Posts tagged 'StringTokenizer'

Tag Archives: StringTokenizer

Java StringTokenizer countTokens() Method

This method is used to count the number of the tokens from current token position to the last token

Signature

public int countTokens()

Parameters

NA

Return

Return the number of tokens available from specific token position

Example

Initially token position was before the first word “Arise” so on calling st.countToken() returns 11.
on calling st.nextToken() position of token is incresed by one and it is on “Arise” from this position new token count is 10.

Java StringTokenizer nextElement() Method

This method returns next token from stringTokenizer object this method work same as nextToken() only the return type of this method is object instead of String

Signature

public Object nextElement()

Parameters

NA

Return

Return next token from StringTokenizer object

Throws

NoSuchElementException – If there is no token in StringTokenizer object then it throw this exception

Example

Another Example

Java StringTokenizer nextToken() Method

This method returns next token from stringTokenizer object

Signature

public String nextToken()

Parameters

NA

Return

Return next token from StringTokenizer object

Throws

NoSuchElementException – If there is no token in StringTokenizer object then it throw this exception

Example

Result

Java StringTokenizer hasMoreToken() Method

This method is used with StringTokenizer object to check whether there is more token or not
For example
StringTokenizer st=new StringTokenizer(“Hello Friends”);
There are two tokens Hello and Friends. At starting hasMoreToken() point before the Hello Token so calling this method will return true at first.
To get next token we use nextToken()view method.
After getting token Friends, again calling hasMoreToken() it return false.

Signature

public boolean hasMoreToken()

Parameters

NA

Return

Return true if there is more token else return false

Example

Result

St object is pointing before the Hello so calling st.hasMoreTokens() will always return true.

Managed by MochaHost - Fast & Easy WordPress Hosting