How to Convert Char to String in Java?

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

In Java char is a primitive data type and String is an object that represents a sequence of char values. In this article we'll see multiple ways to Convert Char to String in Java. Some of the key ways to convert char to string in Java are:

  • String.valueOf() method
  • Character.toString()

Concatenation of a string with a char String.valueOf() and Character.toString() are the most used methods to convert char to string in Java.

Java char to string using String.valueOf() method

The String.valueOf() method is used to convert different types of values to string. This method accepts different kinds of values such as char, int, boolean, double, float, etc.

For our article, we will use this method to convert char to string in Java. We will pass a char value and the method will return a string version of the char value.

Syntax:

Example: To convert char to string using String.valueOf() method.

Output:

Java char to string using Character.toString() method

Second method to convert char to string in Java is Character.toString(). For converting a char to string, we will pass the char to the method as an argument.

Calling the method by passing a char as an argument.

Syntax:

Example: To convert char to string using toString() method.

Output:

Java char to string using Concatenation of strings

Another way to convert char to string in Java is by concatenating the char to an empty string. Let's have an example to understand this.

Output:

Convert string to char Array

In Java, we can use the toCharArray() method to convert a string to char Array.

Syntax:

Example To convert a string to char array using the toCharArray() method.

Output:

Conclusion

  • A char is a primitive data type that stores a single character value while a string stores a sequence of char values.
  • We can convert char to string in Java using the following ways: String.valueOf() method, Character.toString() method and Concatenation of strings.
  • A string can be converted to a char array in Java using the toCharArray() method.