How to Convert Char To String in Java
Java is an object-oriented programming language with a high level of abstraction. It is a general-purpose programming language designed to allow programmers to write code once and execute anywhere. This means that compiled Java code can run on any platform that supports Java without requiring recompilation.
Character is a single 16-bit Unicode character is represented by the char data type. It has a value range of ‘/u0000’ (or 0) to ‘/uffff’ (or 65,535 inclusive). The Unicode system’s lowest range is “u0000”. Characters are stored using the char data type. A string is a collection of characters that may be used as a literal constant or as a variable. A string is a data type that is frequently implemented as an array data structure of bytes (or words) that records a succession of items, most commonly characters. So today with the basic knowledge of Character and Strings let us start with the tutorial on How to Convert Char to String in Java.
What’s The Approach?
- Create a
Class
andMain
Function.
- Declare a char variable and store a character in it.
- Use the function “
Character.toString(char_variable);
” to convert thechar
toString
- Print the
String
value using the commandSystem. out.println();
Also Read: How to convert String to int in Java
Java program to Convert Char to String
/* * TechDecode Tutorials * * How to Covert Char to String * */ public class Char_To_String { public static void main(String[] args) { //input character variable char c = 'a'; //Using toString() method String s = Character.toString(c); //print string value System.out.println("String is: " + s); } }
Output:-