Alternatives for WordUtils.capitalize?

user7517257 :

I'm trying to capitalize every word in a string using WordUtils.capitalize(String) because it does exactly what I wanted. However it is now deprecated.

What method should I use instead? Or do I have to write my own method?

KevinO :

The implementation in commons-lang3 is deprecated. However, the same method is implemented in commons-text. Therefore, you may use essentially the same method, but will need to add a new .jar file and adjust the import statement.

From the javadoc of org.apache.commons.lang3.text.WordUtils:

as of 3.6, use commons-text WordUtils instead

If using Maven (or similar), add the following:

<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-text</artifactId>
  <version>1.1</version>
</dependency>

The reference for Commons Text: Apache Commons Text is a library focused on algorithms working on strings.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=442694&siteId=1