• Post Reply Bookmark Topic Watch Topic
  • New Topic

StringUtils.trimAllWhiteSpace() or String.replaceAll()

 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Julio Delgado Mangas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!