How to convert char to String in Java
Published: July 11, 2009 , Updated: February 27, 2012 , Author: mkyong
Here’s a Java program to show you how to convert Char to String or vise verse.
package com.mkyong; public class ConvertCharToString { public static void main(String[] args) { String website = "http://www.mkyong.com"; //convert a String into char char charData = website.charAt(11); System.out.println(charData); //convert char back to String String temp = Character.toString(charData); if ("m".equals(temp)) { System.out.println("match"); } } }
Output
m match







this example seems more to be for converting strings to char and why are throwing in the if statment? just confuses the issue
“website.charAt(11)” will return a char and later use “Character.toString()” to convert char to String.
The if statement is used to show that the char is converted into string and can be used for string compare.