What is StringUtils.uncapitalize in Java?

uncapitalize is a static method of the StringUtils class that is used to convert the first character of the given string to lowercase, as per Character.toLowerCase. The remaining characters of the string are not changed.

For example:

string = "AbaBAaaabBbCCcaC"

uncapitalize returns abaBAaaabBbCCcaC, changing the case of the first character to lowercase.

StringUtils is defined in the Apache Commons Lang package. Apache Commons Lang 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-lang3</artifactId>
            <version>3.12.0</version>
</dependency>

Note: For other versions of the commons-lang package, refer to the Maven Repository.

You can import the StringUtils class as follows:

import org.apache.commons.lang3.StringUtils;

Syntax

public static String uncapitalize(final String str)

Parameters

  • final String str: the string to be uncapitalized

Return value

This returns an uncapitalized string.

Code

import org.apache.commons.lang3.StringUtils;
public class Main {
public static void main(String[] args) {
System.out.println(StringUtils.uncapitalize("AbaBAaaabBbCCcaC"));
System.out.println(StringUtils.uncapitalize("'hello'"));
}
}

Output

abaBAaaabBbCCcaC
'hello'

The second string remains the same as the input string because the first character is in single quotes.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources