Online Java Compiler By
JavaTpoint.com
public class JavaCharacterToStringExample_2 { public static void main(String[] args) { // Create two char primitives ch1 and ch2. char ch1, ch2; // Assign the values to ch1 and ch2. ch1 = 'f'; ch2 = 'e'; // Create two String objects s1 and s2. String s1, s2; // Assign the String values of ch1 and ch2 to s1 and s2. s1 = Character.toString(ch1); s2 = Character.toString(ch2); String str1 = "The string value of " + ch1 + " is given as:" + s1; String str2 = "The string value of " + ch2 + " is given as: " + s2; // Print the values. System.out.println( str1 ); System.out.println( str2 ); } }
Output