how to use StringTokenizer class using collections in java
Previous | Home | Next |
package r4r.co.in;
import java.util.*;
public class CollectionsExample {
/**
* @param args
*/
public static void main(String[] args) throws NullPointerException, NoSuchElementException
{
// TODO Auto-generated method stub
try
{
String string = "r4r tutorials development softwares"; // defined a string
StringTokenizer st = new StringTokenizer(string); // passed the string to the StringTokenizer constructor
while(st.hasMoreTokens()) // loop till the st has more tokens to offer
{
System.out.println(st.nextToken()); // displaying the tokens
}
}
catch(NullPointerException e)
{
e.printStackTrace();
}
catch(NoSuchElementException e)
{
e.printStackTrace();
}
}
}
The output of the above example is:
r4r
tutorials
development
softwares
Previous | Home | Next |