8:31 pm - Thursday April 27, 2017

Program for creating string counttokens using int countTokens() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

Program for creating string counttokens using int countTokens() method

Example Program


import java.util.StringTokenizer;

public class StringTokenizerDemo {

	public static void main(String[] args) {

		// create String tokenizer

		StringTokenizer st = new StringTokenizer(
				"Java is the best programming language");

		// counting tokens

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

	}

}

 

Output

Total tokens :6

 

Explanation

public int countTokens()

Calculates the number of times that this tokenizer’s nextToken method can be called before it generates an exception. The current position is not advanced.

Returns:

the number of tokens remaining in the string using the current delimiter set.

See Also:

nextToken()

BACK

Filed in: Z-A All Java Codes

Comments are closed.