File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes StringTokenizer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringTokenizer" Watch "StringTokenizer" New topic


Kalyani Nayak

Joined: Jan 01, 2006
Posts: 25
It is very surprising but I faced one problem using StringTokenizer class.
I used 2 parameter constructor i.e. StringTokenizer("This is my : first token ::: This is my : second token",":::");
Now in above case if I tokenize the string it gives me 4 tokens as

This is my
first token
This is my
second token

Instead it should give me

This is my : first token
This is my : second token

I am confused why it is tokenizing for single ':' as my seperator token is ':::'

Any body has idea ?
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 237
I'm also puzzled i tried the same thing with some thing like this

And my output turned out to be
This is my
b first token
c This is my
dj second token

May be the delim matches the first occurence .Anyways I would do this with String Split or regex

Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
The second parameter is a list of characters to use as delimiters, not a String to be used as a delimiter.

The String.split method is probably better for what you want to do.

I agree. Here's the link:
subject: StringTokenizer
It's not a secret anymore!