File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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 is another possibility if the parsing is reasonably simple.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: String Tokenizer or Regex