• Post Reply Bookmark Topic Watch Topic
  • New Topic

How String tokeinzer is advantegous then Strings utility method  RSS feed

 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a file ,which contains the lines of records wiht comma seprated.
I want to tokeniz the lines read from the file ,
I am in dillema which one should use

Either I should go for either "String.split()" ro StringTokenizer;

Could any one please explain me the advantage to use any of these and which should be prefferable and will take less amount of time.
 
Rajesh Narkhed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps this discussion should answer your question...

http://forum.java.sun.com/thread.jspa?threadID=772447&messageID=4400545
 
sharada dantu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For most string splitting tasks, the String.split() method is much easier and more natural to use than the StringTokenizer class.

However, StringTokenizer is still useful for some tasks. For example, an overloaded StringTokenizer constructor allows you to specify that the tokens to be returned include the delimiter characters themselves.

Hope this helps.

-Sharada
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have never used either, you should do it both ways.
Just to learn how to do it.

Normally you should judge this task on time it takes to implement it and time it may take to maintain the code you've created.

Only in rare cases will the execution time (or execution size) of the code you create actually become an issue (for example: if it's part of a compiler that gets used constantly). Only then should it be used as a data point in your decision of what to do.

And of course, most people just do it the way they know how. =)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!