Using the StringTokenizer class

StringTokenizer class might be very usefull especially when you read a text data from a socket. Here is an example to show how we can use this class.

package tokenizer;

import java.util.StringTokenizer;

 * @author nurhak.kaya
public class Tokenizer {

    public static void main(String[] args) {

        String text1 = "This is a sample text!";
        String text2 = "30.01.2012";

        StringTokenizer st1 = new StringTokenizer(text1);
        StringTokenizer st2 = new StringTokenizer(text2, ".");

        while (st1.hasMoreElements()) {
            String string1 = (String) st1.nextElement();
            System.out.println(" --> " + string1);


        while (st2.hasMoreElements()) {
            String string2 = (String) st2.nextElement();
            System.out.println(" --> " + string2);


Post a Comment

Popular posts from this blog

Solution for "Can not obtain Oracle client information from registry"

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"

Getting Umbraco Content - IPublishedContent vs IContent vs Node vs Document