aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: (Contractors) Regex vs. String.startsWith Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: (Contractors) Regex vs. String.startsWith" Watch "NX: (Contractors) Regex vs. String.startsWith" New topic
Author

NX: (Contractors) Regex vs. String.startsWith

Jeff Wisard
Ranch Hand

Joined: Jan 07, 2002
Posts: 89
Hello,
My findByCriteria method is described in the documentation as (from the javadoc of DBAccess):


Returns an array of record numbers that match the specified criteria. Field n in the database file is described by criteria[n]. A null value in criteria[n] matches any field value. A non-null value in criteria[n] matches any field value that begins with criteria[n]. (For example, "Fred" matches "Fred" or "Freddy".)
@param criteria The field-by-field criteria for the record search.
@return The record numbers found for the given criteria.

Since the string comparison can be done very easily with the String.startsWith method, is there any advantage to using regular expressions here? It seems like that might be overkill...
Thanks!


Jeff Wisard<br />Sun Certified Java Programmer (Java 2)<br />Sun Certified Web Component Developer
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
Originally posted by Jeff Wisard:
Hello,
My findByCriteria method is described in the documentation as (from the javadoc of DBAccess):

Since the string comparison can be done very easily with the String.startsWith method, is there any advantage to using regular expressions here? It seems like that might be overkill...
Thanks!

theres pretty much no advantage if you plan to read a single value, then compare, and then move to the next value, and so on until you're done with the file.
but if you plan to have regex run through the file at once it comes at a price, unfortunately its not as cheap as calling startsWith, theres a bit of work involved, I cant tell you performance wise yet, because mainly thats currently whats holding me up right now, amongst some little things, I'm keen to know the difference in performance between reading the entire file and matching that, and a simple startsWith, and yes I'm well aware performance is not an issue on this assignment, I'm just interested.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: (Contractors) Regex vs. String.startsWith