Uncapitalize first character of all words in a String in Java using Apache Commons Text
Tags: Apache Commons Apache Commons Text WordUtils String
Introduction
In this article we will explore the WordUtils.uncapitalize() method of Apache Commons Text library to uncapitalize a String. With Java code example we will learn how to use the WordUtils.uncapitalize() method to convert the first character of all words in a String to lowercase character.
Setup Apache Commons Text in Java project
If you are using Gradle build then add the following dependency configuration into build.gradle file.
compile group: 'org.apache.commons', name: 'commons-text', version: '1.9'
Or add the following dependency XML tag to pom.xml file if you are using Maven build.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
Or download commons-text-1.9.jar file from Apache Commons Text download page at commons.apache.org
Java example code how to use org.apache.commons.text.WordUtils.uncapitalize()
import org.apache.commons.text.WordUtils;
public class WordUtilsUncapitalizeExample {
public static void main(String[] args) {
String result1 = WordUtils.uncapitalize("Simple Solution");
String result2 = WordUtils.uncapitalize("SIMPLE SOLUTION");
String result3 = WordUtils.uncapitalize("sIMPLE sOLUTION");
String result4 = WordUtils.uncapitalize("simple solution");
System.out.println(result1);
System.out.println(result2);
System.out.println(result3);
System.out.println(result4);
}
}
simple solution
sIMPLE sOLUTION
sIMPLE sOLUTION
simple solution
Happy Coding 😊