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


Chandra Moulee

Joined: Sep 26, 2005
Posts: 16
I have the StringTokenizer class.I create an StringTokenizer object.This is what i do.
String s="a,,,b";
StringTokenizer s1=new StringTokenizer(s,",");
It should give me 5tokens.But it is giving me only 1.
,,, should be treated as null rite.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

No, that will give you two tokens ("a" and "b").

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
If you're JDK version is >1.4 it's better to use String's split method :
"a,,,,b".split(",") will return an array of 5 String objs.
[ September 29, 2005: Message edited by: Seb Mathe ]

Regards,<br />Seb<br /> <br />SCJP 1.4
I agree. Here's the link:
subject: SwingTokenizer
It's not a secret anymore!