How to Convert Char to String in Java


In this example we will show how to convert a character to string using the toString() method.

Source Code

package com.beginner.examples;

public class CharToStringExample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Character chA = 'a';
		
		if(!chA.equals("a"))
		{
			System.out.println("ChA is not a string!");
		}
		
		String strA = chA.toString();
		if(strA.equals("a"))
		{
			System.out.println("strA is a string!");
		}
	}

}

Output:

ChA is not a string!
strA is a string!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments