aspose file tools*
The moose likes Beginning Java and the fly likes catching null in a StringTokenizer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "catching null in a StringTokenizer " Watch "catching null in a StringTokenizer " New topic
Author

catching null in a StringTokenizer

swatione chowdary
Greenhorn

Joined: Apr 07, 2005
Posts: 27
can any one give me the solution on this

i have a situation like this ,

i have a String like this

~~~~data~~~name~~~~hi~how~are~you~

where '~' is a delimeter.

i passed this string in to a StringTokenizer

in a StringTokenizer object if two delimeters are adjacent i have to consider it as null token.

as the methods( nextToken() , nextElement() ) in StringTokenizer are not returning null.

how can i achieve it even through programmetically.

can any one give this logic.
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

Maybe it's giving you an empty string instead of a null object-reference variable.

Compare the results against the empty String: ""

Kaydell
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look at the "other" constructor on StringTokenizer. You can tell it to return the delimiters and the data. It can be a bit tricky to use the results. Show us what you make!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
swatione chowdary
Greenhorn

Joined: Apr 07, 2005
Posts: 27
hear is the code for this problem, you can ask questions where you cant understand.

i request every one to post the solutions like this.

the code which is in the while is the actual code for the question raised.

i invite your comments.


i think that it is not possible to do with the two previous replyes.





[edit - added code tags and broke long line]
[ June 27, 2007: Message edited by: David O'Meara ]
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
ok,I dont know if i am clear with your "actual doubt" but,
below shown is the link i hope it can help you to solve your problem .


http://forum.java.sun.com/thread.jspa?threadID=419339&messageID=1866816
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm not sure all of the code is required, a comment like "check the API for StringTokenizer will help, specifically the constructor that accepts a boolean".

Viola, solved
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
As far as I know even the modern String.split does the trick (giving empty strings instead of null's).
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
This test code shows the difference between a StringTokenizer object and the String split() method.



I think in your case you want to split() the input String.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: catching null in a StringTokenizer
 
Similar Threads
StringBuffers and Tokenizers
SwingTokenizer
StringTokenizer cannot split String with tabs?
StringTokenizer and consecutive delimiters
could someone explain stringTokenizer