JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Java StringTokenizer Token Count Sample Code


Description:

Below example shows no of token count after breaking the string by delimiter. You can get the count by using countTokens() method.


Code:
package com.myjava.stokenizerr;

import java.util.StringTokenizer;

public class MyTokenCount {
    public static void main(String a[]){
        String msg = "This program gives sample code for String Tokenizer";
        StringTokenizer st = new StringTokenizer(msg," ");
        System.out.println("Count: "+st.countTokens());
    }
}

Example Output

Count: 8

Other StringTokenizer Class Examples

Knowledge Centre
Preemptive scheduling Vs Time slicing?
Preemptive scheduling: The highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence.

Time slicing: A task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
Famous Quotations
It is amazing what you can accomplish if you do not care who gets the credit.
-- Harry Truman

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.