uncapitalize
is a static method of the WordUtils
class that is used to uncapitalize all delimiter separated words in a string. Each word’s initial character is the only character that is altered.
Note:
- The set of delimiters that separate the words can be passed to the method.
- If no delimiters are specified, then the whitespace is considered the delimiter by default.
WordUtils
is defined in the Apache Commons Text
package. Apache Commons Text
can be added to the Maven Project by adding the following dependency to the pom.xml
file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
For other versions of the commons-text package, refer to the Maven Repository.
You can import the WordUtils
class as follows:
import org.apache.commons.text.WordUtils;
public static String uncapitalize(final String str, final char... delimiters)
final String str
- string to be capitalizedfinal char... delimiters
- set of delimitersReturns a new uncapitalized string.
import org.apache.commons.text.WordUtils;public class Main {public static void main(String[] args) {String string = "Hello eduCATive,How ARe yOU?";System.out.print("Delimited by whitespace - ");System.out.print(WordUtils.uncapitalize(string));System.out.print("\nDelimited by comma (,) - ");System.out.print(WordUtils.uncapitalize(string, ','));}}
string = "Hello eduCATive,How ARe yOU?"
Applying the uncapitalize
method would result in hello eduCATive,How aRe yOU?
. The first letter of each word separated by a space is converted to lowercase.
string = "Hello eduCATive,How ARe yOU?"
,
Applying the uncapitalize
method would result in hello eduCATive,how ARe yOU?
. The first letter of each word separated by a comma is converted to lowercase.
Delimited by whitespace - hello eduCATive,How aRe yOU?
Delimited by comma (,) - hello eduCATive,how ARe yOU?
RELATED TAGS
CONTRIBUTOR