This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

java.util.regexp

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. How are the classes in this package different from what I can do with the String class *specifically with the match,replace and split* methods. Why would I want to use Pattern or Match over String?.
Thanks!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It takes time to parse a new pattern so the JVM can understand what it's supposed to be looking for. The String methods you cite each compile a new Pattern internally using the regex String argument whenever they are invoked. If you're going to use the same regex String more than once, it's more efficient to just compile it into a Pattern once, and use the Pattern and Matcher methods as many times as necessary. But if performance isn't a concern, or you're only going to use the regex once, then the String methods are a bit easier to use.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic