Reputation: 1546
What is the difference between:
${obj.title.replaceAll(' ', '-')
and thymeleaf specific:
${#strings.replace(obj.title, ' ', '-')}
I know that in first example I use standard String method and in second one I use the Strings class from Thymeleaf. Which one is preferred and why? Is there any specific case when methods from String class cannot be used and they should be replaced with Strings equivalent?
Upvotes: 2
Views: 254
Reputation: 1555
Here are a few differences:
strings.replace
first param doesn't need to be string and can be nullstrings.replace
second param, the one you're searching for, is not a regex while the sdk String#replaceAll
will work with regexYou can find cases when the Thymeleaf seems preferable, for eg. when you don't want to dirty the code with null checks or toString calls. That being said I would always use the SDK API because
Upvotes: 2