Java Convert Character to String using Apache Commons Lang

Tags: Apache Commons Apache Commons Lang CharUtils Convert Character String

In this Java tutorial we learn how to Convert a Character object to a String object using the CharUtils of Apache Commons Lang library.

How to add Apache Commons Lang 3 library to your Java project

To use the Apache Commons Lang 3 library in the Gradle build project, add the following dependency into the build.gradle file.

implementation 'org.apache.commons:commons-lang3:3.12.0'

To use the Apache Commons Lang 3 library in the Maven build project, add the following dependency into the pom.xml file.

<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-lang3</artifactId>
  <version>3.12.0</version>
</dependency>

To have more information about the Apache Commons Lang 3 library you can visit the library home page at commons.apache.org/proper/commons-lang/

How to convert Character object to String object in Java

The Apache Commons Lang library provides the method CharUtils.toString() to convert a Character object into a String object that contains only one character. You can learn how to use the CharUtils.toString() method via the example code below.

ConvertCharacterToString.java

import org.apache.commons.lang3.CharUtils;

public class ConvertCharacterToString {
    public static void main(String... args) {
        Character character = new Character('S');

        String result = CharUtils.toString(character);

        System.out.println("Converted String value: " + result);
    }
}
The output is:
Converted String value: S

Happy Coding 😊