wood burning stoves 2.0
The moose likes Performance and the fly likes String Tokenizer or Regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "String Tokenizer or Regex" Watch "String Tokenizer or Regex" New topic

String Tokenizer or Regex

Ashwath Rangan

Joined: Jan 30, 2007
Posts: 6
I need to read text from a CSV file where i use "|" as seperators. I am wondering if i should be using String Tokenizer or Regular expressions. Can any body help me in deciding wich is faster.

Thanks in advance
Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
Regular Expression are faster.

Thanks and Regards,
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
It doesn't matter whether StringTokenizer or split() is faster; neither one is the right tool for this job. For standard CSV data, I would recommend a dedicated CSV parser/tokenizer, but it sounds like Stephen Ostermiller's StringTokenizer replacement will suit your needs better:

Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

If you are reading from files (as in FileInputStream() or FileReader()) then java.io.StreamTokenizer is another possibility if the parsing is reasonably simple.
I agree. Here's the link: http://aspose.com/file-tools
subject: String Tokenizer or Regex
It's not a secret anymore!