Home Java Java-conversion Convert Character into a String



Convert Character into a String
Posted on: June 15, 2007 at 12:00 AM
In this section, you will learn how to convert a char into a string type data.

Convert Character into a String

     

In this section, you will learn how to convert a char into a string type data. The java.lang package provides the functionality to convert a character into a string. 

Code Description:

This program takes a character at the console and converts it into a string format using by the toString() method. This method converts the character into an integer type data. The character class wraps a value of the primitive type char in an object. The toString method returns a string object representing this character's values.

Here is the code of this program:

import java.io.*;
import java.lang.*;

public class CharToString{
  public static void main(String args[])throws IOException{
  BufferedReader read = 
 
new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter a Character:");
  String s = read.readLine();
  char c = s.charAt(0);
  System.out.println("Character value is " + c);
  String s1 = Character.toString(c);
  System.out.println("String value is " + s1);
  }
}

Download of this program:

Output of this program.

C:\corejava>java CharToString
Enter a Character:
R
Character value is R
String value is R
C:\corejava>

Related Tags for Convert Character into a String:
javacstringideormdataformfunctionconsoleconvertfuniointegermethodformattypecharviusingoleintthisidpackagefunctionalcharactertostringforunccteprogramtoramlaneitdeslipeinrmmnttrososjpackesfuncagemeintoproackssoatpacrackishafunctionalityandaractconsstrrtrtsvassriringthavstprndonogrolo


More Tutorials from this section

Ask Questions?    Discuss: Convert Character into a String   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.