• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

StringUtils.trimAllWhiteSpace() or String.replaceAll()

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Working on Springs framework, if we want to remove "all" spaces from a string, would it be costlier to use replaceAll() method of String object than using trimAllWhiteSpaces() from StringUtils of Spring API?

Regards
 
author & internet detective
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Himanshu,
I think both would be so fast it wouldn't matter. If you disagree, you could time it.

I would use trimAllWhiteSpaces because it is clearer as to the intent. Maybe they use a regexp, maybe they use a loop. The nice thing is you don't need to know. And if they tune it in the future, you don't have to change anything.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The nice thing is you don't need to know.



I wouldn´t consider this to be a feature. It´s always better to know what is happening behind the scenes, and more when we are talking about performance.

And if they tune it in the future, you don't have to change anything.



I totally agree with this, of course modularity and reusability must be enforced, but not at the expense of understanding.

I´ve seen too many so called "Java Developers" that have never programmed with pointers or study data structures from a theoretical point of view, and the lack of understanding about what a hast table or a double linked list are, make them awful engineers.

If you make an idiot proof language, you´ll have idiots using it.

Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic