Trusted answers to developer questions

What is WordUtils.uncapitalize in Java?

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

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;

Syntax

public static String uncapitalize(final String str, final char... delimiters)

Parameters

  • final String str - string to be capitalized
  • final char... delimiters - set of delimiters

Returns

Returns a new uncapitalized string.

Code

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, ','));
}
}

Example 1

  • string = "Hello eduCATive,How ARe yOU?"
  • delimiter =

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.

Example 2

  • string = "Hello eduCATive,How ARe yOU?"
  • delimiter = ,

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.

Expected Output

Delimited by whitespace - hello eduCATive,How aRe yOU?
Delimited by comma (,) - hello eduCATive,how ARe yOU?

RELATED TAGS

java
wordutils
Did you find this helpful?