StringTokenizer in java sample program with example

     

StringTokenizer in java

                      
                                     In java the StringTokenizer class is used to break a string into a number of tokens . It is the simple way to break the string.It presents in java.lang.Object package.

Example:
                Welcome to java, world 

Java program:
import java.util.StringTokenizer;
public class StringToken {
            public static void main(String[] args) {
                        String strname = new String(" Java is a high-level programming language originally developed by sun microsystem.");  
                        StringTokenizer st1 = new StringTokenizer(strname," ") ;      //by using space” “ we are splitting string
                        while (st1.hasMoreTokens()) {
            System.out.println(st1.nextElement());                                 
                        }
            }
}

output:

Java
is
a
high-level
programming
language
originally
developed
 by
 sun
 microsystem. 


Interview questions:
What is String Tokenizer?
Why we are using String Tokenizer?
Write a sample program on String Tokenizer in java?




EmoticonEmoticon