This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

NX: (Contractors) Regex vs. String.startsWith  RSS feed

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!